This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate problem" Watch "Hibernate problem" New topic
Author

Hibernate problem

Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Hi, constantly I have a problem of throwing LazyInitializationException.

Either if I use a Spring or low-level comunication with database the mentioned exception is thrown whenever
I try to retrieve an object using -- load(Class klass, id) --.
If I try to retrieve using createQuery(...) method it's than ok, no exception occurs.
Here is the portion of code where I try to retrieve an object using Spring integration :



Where ImprovedEventDao extends abstract class AbstractSpringDao, which extends HibernateDaoSupport :



In low level db comunication, my method for storing and retrieving object is :





where startoperation() mmethond perform obtaining SessionFactory, Sesion and Transaction. Also I get the mentioned
Exception. What is the problem? If I not close session after inserting data, and not commit second startoperation() and
commit() method, I do not get an exception, neither if I use createQuery() method.. But then, two distinct operation occurs during the same session!?
If I use Spring, there is no choice, and each operation will occurs in context of particular Session and Transaction.
so what is the problem!?!?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hibernate problem
 
Similar Threads
Controlling Hibernate Session with Spring
LazyInitializationException [spring + struts2]
type casting
Multiple level logic:iterate
Very Strange Error with Mapping. Please help