0

I initialize lazy relations by calling loadLazyRelations method, in which I initialize all relations from entity using isEmpty() method:

public void loadLazyRelation() {
        relation1.isEmpty();
        relation2.isEmpty();
        relation3.isEmpty();
        relation4.isEmpty();

        if(manyToOneObj != null) {
            manyToOneObj.getLazyRelation().isEmpty();
            manyToOneObj.getLazyRelation().isEmpty();
        }

}

I call this method inside entity.getFull() from CRUD class. It works fine, it fully loads the entity and relations. I saved the initialized entity, but when I'm accessing it from the other method, I'm getting

 org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: relation, could not initialize proxy - no Session

Where is the problem?

yaw
  • 303
  • 2
  • 11
  • use a `@Transactional` annotation at the manager/service method where `loadLazyRelation()` has been invoked – Yuriy Tsarkov Jan 31 '20 at 13:09
  • Look at [this](https://stackoverflow.com/questions/11746499/how-to-solve-the-failed-to-lazily-initialize-a-collection-of-role-hibernate-ex) – SternK Jan 31 '20 at 13:46
  • How can anyone be expected to answer this from the information given. Post all the relevant code with a clear explanation of the problem. – Alan Hay Feb 01 '20 at 11:34

0 Answers0