JPA now exists and for new projects, you probably want to use it's annotations, though annoyingly they are often subtly different. Another fact, which contributes to this error is similar/same names used by JPA and hibernate. Though it's one of the simplest fixes you have to make, this can take anywhere between few minutes to few hours to actually find that this is due to the wrong package or incorrect import of annotation. That's all about how to fix "Exception in thread “main” : Unknown entity: Person" error in Hibernate, JPA and Spring-based web application. Don't import If you are new to JPA, you can further see these Hibernate and JPA online courses to learn more about Java Persistence API. Solution : Use to annotate your entity beans. java :550)Ĭause: Incorrect import for annotation, My entity class was incorrectly annotated by annotation rather than, which comes with JPA. onSaveOrUpdate( DefaultSaveOrUpdateEventListener. performSaveOrUpdate( DefaultSaveEventListener. entityIsTransient( DefaultSaveOrUpdateEventListener. saveWithGeneratedOrRequestedId( DefaultSaveEventListener. saveWithGeneratedOrRequestedId( DefaultSaveOrUpdateEventListener. java :121)Īt .DefaultSaveOrUpdateEventListener saveWithGeneratedId( AbstractSaveEventListener. For a newbie Java or hibernate developer it’s really hard to understand which Entity annotation to use, shouldn't be in, but instead it's .īy the way, if you are using the auto-complete functionality of Eclipse IDE, then you can blame it on them, alternatively, you can configure your preferred import in Eclipse.Įrror : Exception in thread “main” : Unknown entity : PersonĪt. Unfortunately, this error is not easy to spot, the import seemed completely appropriate to many programmers. Once I fixed this import issue, everything went smoothly. I checked everything, from Spring configuration file applicationContext.xml, Hibernate config file, my Entity class, and DAO class to see whether my Entity class is annotated or not, but I was still getting this error message.Īfter some googling, I eventually find that it was an incorrect import that was causing this error.īoth hibernate and JPA has annotation and somehow Eclipse was automatically importing instead of annotation. I was using Spring 3 and Hibernate 3.6 when I got this error, which occurs when addEntity() method was executed. This error message is so misleading that you could easily lose anywhere between a few minutes to a few hours looking at the wrong places. If you have used Hibernate with JPA and using annotation to declare your entity bean then you might have seen this confusing error called ": Unknown entity".
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |