EntityManager getReference no lazy loading

Attempting to save an object that contains a member variable that is a reference to some other object that is not under the current persistence context will not be possible, when this happens, you need to extract the required object and set it in the original to respect the relationship and be allowed to save it.

When I need to do this, I usually use the EntityManager search method, but it will hit the database and select the entire object along with it, which may not be annotated for lazy loading. I was glad to learn about getReference, which, apparently, does not get into the database, but returns a proxy view where only the primary key is available, and that’s really all that is needed for this type of situation.

Unfortunately, after some debugging, I found that I can see all the information about the getReference'd object, and not just the primary key, when I "check" it in Eclipse debugging mode.

Am I missing something? Is debugging mode fooling me? Can it get information similar to the getter method when using a proxy in a link?

Thank you in advance

+4
source share
1 answer

You test it using the Eclipse debugger, the debugger initializes the proxy server. Just turn on SQL logging, run the em.getReference() method and make sure your JPA engine has not followed any instructions.

0
source

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


All Articles