org.hibernate.LazyInitializationException: could not initialize proxy – no Session

I have an object X which has a many-to-one relationship with Object Y. I could see it is working fine in the beginning, but it ended up with problems after some days in production.

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

  • I collect these X objects in a list in my model.
  • I iterate it with Struts tag in view, where I could see this error in log file.

The session I used in model got closed before I iterate the list in UI. The solution was given here. http://stackoverflow.com/questions/345705/hibernate-lazyinitializationexception-could-not-initialize-proxy

Changing the relationship as lazy=false in HBM mapping solves this issue. Make sure it is getting inserted and deleted  properly.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s