Project $$ EnhancerByCGLIB $$ 67a694bd appears in sleep mode

I have a document object mapped to many with a single project object.

When I call document.getProject , in the debugger in the project field of the document object, I see something near Project$$EnhancerByCGLIB$$67a694bd .

How to get a real project object?

+6
source share
2 answers

What you see is a Hibernate-Proxy-Object, which allows sleepers to perform lazy instantiation.

First of all, ask yourself if you really want to access the source object. Usually, you'd better pretend that the proxy is your actual object, and let hibernate do all the magic.

If for some reason you really need the object itself (for example, if you need the exact type), the following code should work:

 if (object instanceof HibernateProxy) { return ((HibernateProxy) object).getHibernateLazyInitializer().getImplementation(); } 

You should know that the result of the above code will give you a separate object that is no longer under hibernate control, so changes to the object will not be synchronized with the database!

+11
source

I was getting an error with this line because I forgot to add parentheses to the method call. Make sure you do not have this:

 document.getProject 

When you really understand this:

 document.getProject() 
+1
source

Source: https://habr.com/ru/post/901098/


All Articles