Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes Problem with LazyInitializationException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem with LazyInitializationException" Watch "Problem with LazyInitializationException" New topic
Author

Problem with LazyInitializationException

Muhammad Ramahy
Greenhorn

Joined: Jun 14, 2011
Posts: 11

I get this exception:


every time I try to execute this code:


I don't know what to do in order to avoid not having session or having multiple sessions and I wish Help

Regards,
Rishi Shehrawat
Ranch Hand

Joined: Aug 11, 2010
Posts: 218

The exception is caused due to detached object. You will have to use session.merge() or session.lock() to attach the object to the session.

http://stackoverflow.com/questions/912659/what-is-the-proper-way-to-re-attach-detached-objects-in-hibernate
Muhammad Ramahy
Greenhorn

Joined: Jun 14, 2011
Posts: 11

It works! thank you, I would also want to say that if I've added to the oneToMany annotation it will also work (that's what I'm currently doing).
nivedan Nat
Greenhorn

Joined: Jul 22, 2011
Posts: 2
Hi

But adding FetchType.Eager defeats the purpose of Lazy Loading. Depends where your using this object, probably associate the entity into session so that lazy loading can happen.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with LazyInitializationException
 
Similar Threads
Sql Exception: inconsistent datatypes, need help
Hibernate 3: java.sql.SQLException: Field 'passwordConfirmation' doesn't have a default value
org.hibernate.MappingException : Unknown Entity?
hibernate.AssertionFailure collection [] was not processed by flush()
How to create a new excel file on server