Pritam Banerjee
Pritam Banerjee

Reputation: 18923

Is there a way to verify that a Lazy loaded object is not in Hibernate session?

Suppose there is a Parent class and I load it using lazy = "true".

Is there a way to verify that the Set is not loaded in the memory before an explicit call is made for it?

public class Parent{
   private Intger parentId;
   Set <Child> child = new HashSet(); 
}

The child class:

public class Child{
   private Integer childId;
   Parent p; 
}

When I load Parent, and before I call parent.getChild(), is there a way to verify that the child is not loaded into the memory?

Upvotes: 4

Views: 630

Answers (1)

Pritam Banerjee
Pritam Banerjee

Reputation: 18923

To test the application the following function was used:

Set<Child> childLazy = parentLazyLoaded.getChild();
Set<Child> childEager = parentEagerLoaded.getChild();

//then use the following methods
System.out.println("Lazy Loaded: " + Hibernate.isInitialized(childLazy));
System.out.println("Eager Loaded: " + Hibernate.isInitialized(childEager));

First one returns false and the second one true.

Upvotes: 3

Related Questions