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?
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?
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:
if (object instanceof HibernateProxy) {
return ((HibernateProxy) object).getHibernateLazyInitializer().getImplementation();
}
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!
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:
document.getProject
When you really mean this:
document.getProject()
Project$$EnhancerByCGLIB$$67a694bd
, as mentioned in the question. Unfortunately I don't remember the details of the message. –
Bogey © 2022 - 2024 — McMap. All rights reserved.