2012-11-23 108 views
2

我試圖運行一個簡單的項目。 我正在努力解決一些問題。 我在數據庫實例中創建了一個簡單的表。 然後,在google教程之後,我在Eclipse中設置了我的項目。JPA + Google SQL + GWT + Eclipse

我提出這個錯誤從本地主機上運行:

[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)]) 

看來,日食鏈接找不到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; 
    } 
} 

回答

0

問題解決了在persistance.xml移除鏈接ORM文件:

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

和增加直接映射到類

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

你的共享文件夾存在(還)客戶端。客戶端無法知道任何關於數據庫的信息。 SQL等。刪除共享到服務器的所有數據庫關係。

+0

移動對象到服務器端不起作用。無論如何,我找到了一些在模型包中添加對象的教程,然後將該包添加到gwt源代碼中,就像將它保留在共享中一樣,對吧? – Berna

+0

不,它不一樣。我不知道你的確切情況,所以我只能推薦將它從共享中刪除。 – Martin

+0

全新項目,但結果相同。奇怪的消息「方法[set]或[get]沒有在對象[com.server.Main]中定義。」可能與配置問題或我的(自動生成的)對象有關? – Berna