0

I have a Hibernate domain object with Lazy child collections. At a certain point I need to force-fetch all Lazy collections so that I have a POJO, with no remaining Hibernate references. This is similar to the following thread, Hibernate: best practice to pull all lazy collections

The hint in that thread is to use Hibernate.initialize() on the Lazy collections that you want to pull. But I see that after calling it on several Lazy children, the Hibernate Proxy objects remain:

enter image description here

For instance you can see after several calls to Hibernate.initialize() I still have

requestor = NedPerson$HibernateProxy$.. requestorOrg = NedOrgUnit$HibernateProxy$..

These references are defined in the HBM XML as fetch="select". There is no lazy spec but they are Lazy by default, as specified here.

<many-to-one name="requestor" class="...NedPerson" fetch="select">
<many-to-one name="requestorOrg" class="...NedOrgUnit" fetch="select">

What am I doing wrong? I need to see plain NedPerson / NedOrgUnitT objects in the debugger after this resolution.

Also, could something like .evict() / .detach() work for my task? Even if Hibernate.initialize() worked, I'd have to invoke it on every single Lazy child, but I want a more dynamic solution. I don't want to use reflection to traverse collection children and apply Hibernate.initialize() on each one, as proposed in this workaround. Is there some simpler modern solution?

gene b.
  • 8,520
  • 12
  • 76
  • 167

0 Answers0