aspose file tools
The moose likes Spring and the fly likes LazyInitializationException(Spring-Hibernate application) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "LazyInitializationException(Spring-Hibernate application)" Watch "LazyInitializationException(Spring-Hibernate application)" New topic

LazyInitializationException(Spring-Hibernate application)

VenkataPrasad Regula
Ranch Hand

Joined: Jun 30, 2011
Posts: 63
I have got two methods in spring-hibernate project. 1)empadd() and 2) empget(). As I execute, the firstone gets executed and for the second one it says LazyInitialization exception. This means the session is getting closed after the first method is executed. To make both the methods run in the same session, I was guided to use OpenSessionInViewInterceptor. This is not a web application. It is a 2-tier application. I am finding on google the class of OpenSessionInViewInterceptor, but I am not knowing how to use it from the client code. What all I need is the same session to be for both the methods.
VenkataPrasad Regula
Ranch Hand

Joined: Jun 30, 2011
Posts: 63
Could someone give a simple but complete sample code. Thanks in advance.
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17260

Where is your transaction boundary. A session is "scoped" to a single transaction, single user, single use case. If you have a use case that covers more than one query, you have to make sure it is still all done in one transaction and one session. Once a transaction is committed, the session is over and done.


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: LazyInitializationException(Spring-Hibernate application)