间歇性地得到 org.hibernate.MappingException: 未知实体:

发布于 2025-01-07 04:56:43 字数 729 浏览 2 评论 0原文

我正在将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走野 2025-01-14 04:56:43

修好了这个。
问题出在我的代码上。我已经保存了用户对象,并单独保存了关联的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文