I am using Java and Hibernate in my project. I am facing a very peculiar problem. Whenever i load an entity, select in not fired on the database, instead whenever i perform some operation on object like get some value, at that time it fires the select which is called lazy loading. But the problem is i have not stated lazy="true" in my HBM file. Also sometimes, load is successful, and then when i try to do some manipulation on the object it gives an error, ProxyInitializationError Session is Closed.
Can check the below link for code base :-
http://pastebin.com/yD9ZM3yH
But if in the actual method i put System.out.println(information.getStudentName()); then the code works properly as the select is fired before the session was closed.
Regards
This is normal behiavior.
when you are using
session.load(Object.class, id)the returned object is proxy class.Just look at my answer here:
What does Hibernate's load() method do for non-existing IDs?
2) you are receiving this error, because as soon as you received your proxy, Hibernate session is closed and proxy initiation throws this exception.
You can read more about it and possible solutions in this technical article.
http://community.jboss.org/wiki/OpenSessionInView
Hope it helps.