Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

LazyInitializationException(Spring-Hibernate application)

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Could someone give a simple but complete sample code. Thanks in advance.
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • 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
 
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic