2011-04-24 62 views
0

我同時通過ANT構建腳本生成通用對我的模型得到這個錯誤:JPA 2:EclipseLink的Ant編譯錯誤

Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.ValidationException 
Exception Description: Entity class [class com.ckd.model.BookModel] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy. 

這裏是我的實體類:

@Entity 
@Table(name = "BOOK") 
public class BookModel implements Serializable 
{ 
    private static final long serialVersionUID = 1L; 

// @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    @Column(name = "ID", unique = true, nullable = false) 
    private Long id; 

    @Id 
    @NotNull 
    @Size(min = 32, max = 32) 
    @Column(name = "HASHID", unique = true, nullable = false) 
    private String hashid; 

    @NotNull 
    @Size(min = 1, max = 255) 
    @Column(name = "TITLE") 
    public String title; 

    @NotNull 
    @Size(min = 1, max = 255) 
    @Column(name = "AUTHOR") 
    private String author; 

    @Lob 
    @NotNull 
    @Column(name = "CONTENT") 
    private String content; 

    @Size(min = 2, max = 3) 
    @Column(name = "LANG") 
    public String lang; 

    // getters and setters here 
} 

我還添加了這種到我的實體,但它沒有區別:

@Entity 
@Access(AccessType.FIELD) 

建立我的項目反對捆綁的EclipseLink庫與G lassfish 3.1或使用來自http://www.eclipse.org/eclipselink/downloads/的EclipseLink v2.x.x獨立庫也沒有區別 - 仍然有上述錯誤。根據Java EE項目要求,我的persistence.xml位於WebContent\META-INf目錄下。它的內容是:

<?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_2_0.xsd" 
    version="2.0"> 
    <persistence-unit name="persistentUnit" transaction-type="JTA"> 
     <description>Persistent Unit for Entity Classes</description> 
     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 
     <jta-data-source>jdbc/prod1</jta-data-source> 
     <class>com.ckd.model.BookModel</class> 
     <exclude-unlisted-classes>false</exclude-unlisted-classes> 
     <properties> 
      <property name="eclipselink.jdbc.DBDictionary" value="mysql(DriverVendor=mysql)" /> 
      <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.MySQLPlatform" /> 
      <property name="eclipselink.jdbc.DBDictionary" value="searchStringEscape=\\" /> 
      <property name="eclipselink.jdbc.QuerySQLCache" value="false" /> 
      <property name="eclipselink.weaving" value="false" /> 
      <property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSessionLog" /> 
      <property name="eclipselink.logging.level" value="FINEST" /> 
     </properties> 
    </persistence-unit> 
</persistence> 

我該如何解決這個錯誤?這是EclipseLink 2.x.x當前實現中的錯誤嗎?

回答

0

這是一個單獨的,未使用的實體條目orm.xml導致上述錯誤。註釋掉未使用的實體條目解決了上述錯誤。

0

你必須取消註釋@Id註釋在類

private static final long serialVersionUID = 1L; 

// @Id <------ HERE 
@GeneratedValue(strategy = GenerationType.AUTO) 
@Column(name = "ID", unique = true, nullable = false) 
private Long id; 
......