I use 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 retuns all Audited Trgs Objects.
The method is :
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 Method above, my result is a Audited Trgs List. Each Trgs Object has of course the correct and releated Audited Factory Object.
But the Problem is, that i have learned that Hibernate Envers always loads Relation LAZY.
So in my Case i have 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 have to initialize 300 Factory Objects. And that costs sooooo much. I have to wait One Minute.
I have learned that it is not possible to Load The Factory Object Eagerly. But i need an other solution. I show this Data in a Dashboad Site (Web Project). The user can not wait one Minute until the data are loading.
Please Help me to solve this Problem. Thanks.