Eclipselink : generate generate table from entities failure

558 views Asked by At

I am having little bit trouble with JPA table generation from entities (on eclipse 4.3 with Dali and eclipselink 2.5.0 ). I have an entity Book, which has several attributes and among them is a Category attribute. the category is also an entity with a name, description and an auto-generated id. the relationship is Book M:1 Category.

here are the relevant snippets

the book...

@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...
}

the category

@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 also generates the Class_ metadata files and they look ok to me...

the book_

@StaticMetamodel(Book.class)
public class Book_ { 

    public static volatile SingularAttribute<Book, Category> category;
    // ....
}

the category_

@StaticMetamodel(Category.class)
public class Category_ {

    public static volatile SetAttribute<Category, Book> books;
    // ....
}

When I choose to generate tables from entities (to see the resultant sql script file), i get this exception

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)

Category is annotated @Entity and it is also included in the persistence.xml file. My question is, what is causing this problem? what have I forgotten? since as far as i can know, Category is an entity.

0

There are 0 answers