Error:
org.hibernate.LazyInitializationException SEVERE: could
not initialize proxy – the owning Session was closed
Code:
System.out.println(resultStudent.getStudentAddress().getCity());
Here the getAddress() returns an Address object and i am trying to get the city of the student using getCity() of Address class. Why do I get the above error?
Just getting the Address object doesn’t throw any error.
Hibernate loads the relationships lazily. So when you are navigating the relationship you need to either have the hibernate session open or fetch the data eagerly. Read the below articles