• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

LazyInitializationException(Spring-Hibernate application)

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could someone give a simple but complete sample code. Thanks in advance.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Mark
reply
    Bookmark Topic Watch Topic
  • New Topic