间歇性地得到 org.hibernate.MappingException: 未知实体:
我正在将 Spring-3.0.5 和 Hibernate-3 用于我正在进行的项目。 我间歇性地收到“org.hibernate.MappingException:未知实体:”,仅适用于“user_roles”域表,并且仅当我尝试在该表中插入记录时才会出现这种情况。所有域对象使用“javax.persistence.Entity”和不“org.hibernate.annotations.Entity” >”,这通常是导致此错误的原因。已为“sessionFactory”bean 提供了值“packagesToScan”。清理和建设该项目并没有帮助。 令人惊讶的是,当部署到 Tomcat 时,我确实在控制台上看到了以下几行:
[AnnotationBinder] Binding entity from annotated class: UserRole
[EntityBinder] Bind entity UserRole on table user_roles
就像所有其他域类一样。
(这个问题似乎是另一个问题的精确副本尚未得到答复。)
非常感谢任何帮助。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
修好了这个。
问题出在我的代码上。我已经保存了用户对象,并单独保存了关联的 user_roles 而不更新用户对象,即我执行了 session.save(userRoles) 而不执行 user.setUserRoles(userRoles)。我现在将代码更改为首先在用户中设置 userRoles,然后仅保存用户对象,这也保存了用户角色。
希望休眠的行为更加一致,错误消息更加友好:)
谢谢。
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.