1

我在从实体生成 JPA 表时遇到了一点麻烦(在 eclipse 4.3 上使用 Dali 和 eclipselink 2.5.0 )。我有一个实体书,它有几个属性,其中有一个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 文件中。我的问题是,是什么导致了这个问题?我忘记了什么?因为据我所知,类别是一个实体。

4

0 回答 0