我同时通过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当前实现中的错误吗?