In Hibernate Envers, all related collections of an entity are loaded lazily, regardless of what fetch type is set. So when auditquerying for an entity that has a collection of other entities (both audited, of course), the collection is a SetProxy
at first (can be seen when debugging).
So, how do I initialize that proxy? Using Hibernate.initialize()
has no effect (I suspect because Hibernate and Envers are using different proxy objects). I know I can initialize the set by iterating over its items, but that isn't an option for me because I have multiple collections in an entity and not to mention the maintenance issues.
I need to initialize them eagerly because I'm accessing the collection at a later point in time when the Hibernate session is already closed (converting the domain objects into dtos).
I'm using Hibernate 3.5.6.
See Question&Answers more detail:os