Single object and lazy loaded fields - workflows

I have the following problem. Class A returns some objects from the database, which are runnables themselves, and runs them in the thread pool. They need to update their state as they start (they update the listeners registered on them). The problem is that they gain access to lazy fields when the object is in a detached state (because the transaction covers only the main thread) - therefore, of course, there are exceptions (com.sun.jdi.InvocationException raised by the call method). I assume that the path annotation method of each of these objects will not work, because the object is already loaded into another transaction. I'm right? How to cope with this situation?

Thanks!

+2
source share
1 answer

It is not possible to access lazy loaded fields in a separate object, you need to bind the object first.

Attach the object to the session by calling session.merge () or entityManager.merge () before trying to access the lazy loaded fields.

+2
source

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


All Articles