Download multi-user communication with Hibernate Envers - impatient / lazy?

I am using Hibernate Envers 4.3.10.Final. I have the following two JPA classes:

public class Factory {
     private int factoryID;
     .... 
}

public class Trgs{
     private int trgsID;

     @ManyToOne(fetch=FetchType.EAGER)
     @JoinColumn(name="fk_factory")
     private Factory factory;
}

I wrote a method that reconfigures all Audited Trgs objects.

Method:

public List<Trgs> readAuditedTrgs (List<Integer> trgsIds) {
      AuditReader reader = AuditReaderFactory.get(entityManager);
      AuditQuery query = reader.createQuery().forRevisionsOfEntity(Trgs.class, true, true);

      query.add(AuditEntity.id().in(ids));
      query.add(AuditEntity.revisionType().eq(RevisionType.ADD));
      query.addOrder(AuditEntity.revisionNumber().desc());
      return  query.getResultList() ;
}

After executing the above method, my result is a list of verified Trgs. Each Trgs object has, of course, a valid and issued Audited Factory object.

But the problem is that I found out that Hibernate Envers always loads Relation LAZY.

So, in my case, I need to iterate over the Trgs list and initialize each Factory object.

 for (Trgs trgs : resultList) {
      Hibernate.initialize(trgs.getFactory());
    }

So, if I had, for example, 300 Trgs objects, I need to initialize 300 Factory objects. And it is expensive. I need to wait one minute.

, Factory . . Dashboad (-). .

, . .

+4
1

, API- Envers AuditQuery, , , . HHH-11479 JIRA .

+1

All Articles