我从实体生成JPA表有点麻烦(在eclipse 4.3上使用Dali和eclipselink 2.5.0)。
我有一个实体Book,它有几个属性,其中有一个Category
属性。
该类别也是具有名称,描述和自动生成ID的实体。关系是
Book M:1 Category
。
这里是相关的片段
这本书......@Entity
public class Book implements Serializable {
// bi-directional many-to-one association to Category
@ManyToOne
@JoinColumn(name = "CATEGORY_ID", nullable = false)
private Category category;
// other attributes, constructors and methods...
}
类别
@Entity
public class Category implements Serializable {
// bi-directional one-to-many association to Book
@OneToMany(mappedBy = "category", cascade = { CascadeType.PERSIST }, fetch = FetchType.LAZY)
private Set<Book> books;
// other attributes, constructors and methods...
}
Dali还会生成Class_元数据文件,它们看起来还不错......
书_
@StaticMetamodel(Book.class)
public class Book_ {
public static volatile SingularAttribute<Book, Category> category;
// ....
}
类别_
@StaticMetamodel(Category.class)
public class Category_ {
public static volatile SetAttribute<Category, Book> books;
// ....
}
当我选择从实体生成表(以查看生成的sql脚本文件)时,我得到此异常
Exception in thread "main" Local Exception Stack:
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b):
org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader:
org.eclipse.persistence.dynamic.DynamicClassLoader@154e92c
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018]
(Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [bookstore] failed.
Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: [class name.kipchumba.obby.bookstore.entities.Book]
uses a non-entity [class name.kipchumba.obby.bookstore.entities.Category] as target entity in the relationship attribute [field category].
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:107)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.buildEntityManagerFactory(Main.java:94)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:80)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:68)
类别带注释@Entity
,它也包含在persistence.xml文件中。
我的问题是,是什么导致了这个问题?我忘记了什么?因为据我所知,类别是一个实体。