File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android 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.
 
Don't get me started about those stupid light bulbs.
 
subject: Problem with LazyInitializationException
 
Similar Threads
hibernate.AssertionFailure collection [] was not processed by flush()
org.hibernate.MappingException : Unknown Entity?
Hibernate 3: java.sql.SQLException: Field 'passwordConfirmation' doesn't have a default value
Sql Exception: inconsistent datatypes, need help
How to create a new excel file on server