项目$$EnhancerByCGLIB$$67a694bd 出现在 Hibernate 中
我有一个文档实体将多对一映射到项目实体。
当我在调试器中调用 document.getProject
时,在文档对象的项目字段中,我看到有关 Project$$EnhancerByCGLIB$$67a694bd
的信息。
如何检索实际的项目对象?
I have a document entity mapped many to one to project entity.
When I call document.getProject
, in debugger, in project field of document object I see something about Project$$EnhancerByCGLIB$$67a694bd
.
How do I retrieve actual project object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我收到一条包含该字符串的错误消息,因为我忘记将括号添加到方法调用中。确保你没有这样的:
当你真正的意思是这样的:
I was getting an error message with that string in it because I forgot to add the parentheses to a method call. Make sure you don't have this:
When you really mean this:
您所看到的是 Hibernate-Proxy-Object,它使 hibernate 能够进行延迟实例化。
首先要问自己的是,您是否真的想访问原始对象。通常,您最好假装代理是您的实际对象,并让 hibernate 完成所有魔力。
如果由于某种原因您确实需要对象本身(例如,如果您需要确切的类型),则以下代码应该可以工作:
您应该意识到上述代码的结果将为您提供一个不再受休眠控制的分离对象,所以对象的改变不会与数据库同步!
What You are seeing is the Hibernate-Proxy-Object, which enables hibernate to do lazy-instantiation.
First thing to ask yourself is, whether you really want to access the original object. Usually you should be better off pretending the proxy is your actual object and let hibernate do all the magic.
If for some reason you really need the object itself (e.g. if you need the exact type), the following code should work:
You should be aware that the result of abovewritten code will give you a detached object which is no longer under hibernate control, so changes to the object will not be synchronized with the database!