JPA exception: Object: … is not a known entity type

后端 未结 11 649

I\'m new to JPA and I\'m having problems with the autogeneration of primary key values.

I have the following entity:

package jpatest.entities;

impor         


        
11条回答
  •  生来不讨喜
    2020-12-10 03:19

    As Charles pointed out in his answer, the problem is not the id generation, but the persistence layer not finding the entity.

    As you, I am also new to JPA. I have tried to write a "Hello World" JPA application using org.eclipse.persistence.jpa.PersistenceProvider when I got this error. The mentioned workaround also worked for me. Moreover, through trial-error I also found that to declare your entities, you must always anotate @entity in each entity and:

    • if you set exclude-unlisted-classes to true, you also have to list the entities within class elements in your persistence.xml
    • if you set exclude-unlisted-classes to false the persistence layer can find the entities regardles of the class element in your persistence.xml.

提交回复
热议问题