I am using Spring-3.0.5 and Hibernate-3 for a project that I am working on.
I intermittently get “org.hibernate.MappingException: Unknown entity: ” for only the “user_roles” domain table and that too only when I try to insert a record in that table. All the domain objects use the “javax.persistence.Entity” and not “org.hibernate.annotations.Entity“, which is generally the cause of this error. The “sessionFactory” bean has been provided the value of “packagesToScan“. Cleaning and building the project has not helped.
Surprisingly when deploying to Tomcat I do see the following lines on the console :
[AnnotationBinder] Binding entity from annotated class: UserRole
[EntityBinder] Bind entity UserRole on table user_roles
just like for all other domain classes.
(This question seems to be an exact copy of another question which has not been answered yet.)
Any help is much appreciated.
Thanks.
Fixed this one.
The problem was with my code. I had saved the user object and was saving the associated user_roles separately without updating the user object i.e. i did session.save(userRoles) without doing user.setUserRoles(userRoles). I now changed the code to first setting the userRoles in user and then just saving the user object which saves the user roles as well.
Wish the hibernate was a bit more consistent in behavior and the error message a bit friendlier 🙂
Thanks.