Search code examples
javaproxyentity-relationshiphibernate-envers

Hibernate Envers: Initializing ListProxy of related objects


I've two entities: User and UserGroup. Relation between them is @ManyToMany and I'm using envers for auditing these entities, class level @Audited annotation is placed on both of them. However, when I try to execute this query:

AuditReader reader = AuditReaderFactory.get(em);
AuditQuery query = reader.createQuery().forRevisionsOfEntity(User.class, false, true);

Returnted user entities have "org.hibernate.envers.entities.mapper.relation.lazy.proxy.ListProxy" collections of user groups with size equal to zero. Calling size() method on these list proxies doesn't initialize them. Any help will be appreciated.


Solution

  • The problem was the following: I started auditing of entities when there already were users and usergroups in the database. Let's say I was modifying some user's groups. This modification caused in addition of corresponding rows in User_AUD and User_UserGroup_AUD tables, but UserGroup_AUD table was still empty. Later when I was querying for revisions of User entity, it wasn't able to find related UserGroup entities since there was no record in UserGroup_AUD table about those user groups.