【问题标题】:JPA + Google SQL + GWT + EclipseJPA + 谷歌 SQL + GWT + Eclipse
【发布时间】:2012-11-23 14:41:00
【问题描述】:

我正在尝试运行一个简单的项目。 我正在努力解决一些问题。 我在数据库实例中创建了一个简单的表。 然后,按照谷歌教程,我在 Eclipse 中设置了我的项目。

我在从 localhost 运行时引发此错误:

[EL Severe]: 2012-11-23 14:23:16.915--ServerSession(1241461653)--Exception [EclipseLink-0] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345):     org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Exception [EclipseLink-60] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [set] or [get] is not defined in the object [com.shared.Main].
Internal Exception: java.lang.NoSuchMethodException: com.shared.Main.get(java.lang.String)
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[id-->main.ID]
Descriptor: RelationalDescriptor(com.shared.Main --> [DatabaseTable(main)])

Exception [EclipseLink-60] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [set] or [get] is not defined in the object [com.shared.Main].
Internal Exception: java.lang.NoSuchMethodException: com.shared.Main.get(java.lang.String)
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[name-->main.NAME]
Descriptor: RelationalDescriptor(com.shared.Main --> [DatabaseTable(main)])

似乎eclipse链接找不到我的对象的getter和setter... 有什么线索吗? 我的persistence.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">

    <persistence-unit name="transactions-optional" transaction-type="RESOURCE_LOCAL">
        <provider></provider>
        <mapping-file>META-INF/eclipselink-orm.xml</mapping-file>
        <properties>
            <property name="datanucleus.NontransactionalRead" value="true"/>
            <property name="datanucleus.NontransactionalWrite" value="true"/>
            <property name="datanucleus.ConnectionURL" value="appengine"/>
            <property name="javax.persistence.jdbc.driver" value="com.google.appengine.api.rdbms.AppEngineDriver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:google:rdbms://myinstance/test_jpa"/>
            <property name="javax.persistence.jdbc.user" value="myuser"/>
            <property name="javax.persistence.jdbc.password" value="mypassword"/>
        </properties>
    </persistence-unit>
</persistence>

我的eclipse-orm.xml:

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.4" xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_4.xsd">
    <entity class="com.shared.Main" access="VIRTUAL">
        <attributes>
            <id name="id" attribute-type="int">
                <generated-value strategy="AUTO"/>
            </id>
            <basic name="name" attribute-type="String">
            </basic>
        </attributes>
    </entity>
</entity-mappings>

我的对象:

package com.shared;

import java.io.Serializable;
import javax.persistence.*;


/**
 * The persistent class for the main database table.
 * 
 */
@Entity
@Table(name="main")
public class Main implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(unique=true, nullable=false)
    private int id;

    @Column(length=50)
    private String name;

    public Main() {
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

【问题讨论】:

    标签: google-app-engine gwt jpa-2.0 google-cloud-sql


    【解决方案1】:

    您的共享文件夹(也)存在于客户端上。客户对数据库一无所知。 SQL 等。删除从共享到服务器的所有数据库关系。

    【讨论】:

    • 将对象移动到服务器端不起作用。无论如何,我找到了一些教程,在模型包中添加对象,然后将包添加到 gwt 源,这与将其保留在共享中一样,对吧?
    • 不,不一样。我不知道你的确切情况,所以我只能建议你把它从共享中删除,sry。
    • 全新项目,但结果相同。奇怪的消息“方法 [set] 或 [get] 未在对象 [com.server.Main] 中定义。”可能与配置问题或我的(自动生成的)对象有关?
    • 我确实坚持不懈地工作。对我来说,无需任何配置,即插即用总是很开心。我认为您做的事情通常是错误的。例如,通常包称为 com.myproject.client。不确定这是否会有所不同,但您仍然不应该直接在 .com 级别上工作。如果没有持久性,这是否有效?我确实写了一个 turorial mwtech74.blogspot.de/2012/08/… 我认为这并不完全是您想要实现的目标,但它表明它应该是多么简单。
    • 问题已通过删除 META-INF/eclipselink-orm.xml 和映射类来解决。顺便说一句,一切都在共享文件夹中工作,因为 gwt 正在注意分离图层。还是谢谢!
    【解决方案2】:

    问题已解决,删除persistance.xml中orm文件的链接:

    <mapping-file>META-INF/eclipselink-orm.xml</mapping-file>
    

    并添加直接映射到类

    <class>org.my.package.MyClass</class>
    

    【讨论】:

      猜你喜欢
      • 2011-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-03
      • 1970-01-01
      • 1970-01-01
      • 2011-05-13
      • 2011-12-20
      相关资源
      最近更新 更多