MyObject myObject = repositoryHibernateImpl.getMyObjectFromDatabase(); //transaction is finished, and no, there is not an option to reopen it ThirdPartyUtility.doStuffWithMyObjectType( myObject );
at this point, you have already determined that it is lazily and eagerly loaded, and a third-party utility will try to call all the methods on your "myObject" instance, this is normal because you do not want to return anything for lazily loaded properties, unfortunately, it does not return null, it throws a LazyInitializationException .
This is because you actually call the method on the Hibernate proxy of your object, and it knows that it did not retrieve this data and throws an exception.
Is it even possible to get a base object with null values ββso that the getter simply returns null and does not throw an exception? Basically separating the object so that Hibernate no longer knows about it. An accessor to an object that is lazily loaded must return null, it cannot return the actual values, we want to be able to convert the object to POJO without creating an object that looks just like an object, and must reassign all the values.
source share