2

我正在尝试运行一个简单的项目。我正在努力解决一些问题。我在数据库实例中创建了一个简单的表。然后,按照谷歌教程,我在 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;
    }
}
4

2 回答 2

1

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

于 2012-11-23T15:10:50.433 回答
0

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

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

并将直接映射添加到类

<class>org.my.package.MyClass</class>
于 2013-02-11T08:46:57.750 回答