-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: newbie load problem.
PostPosted: Sat Aug 12, 2006 5:38 am 
Newbie

Joined: Thu Dec 01, 2005 5:58 pm
Posts: 10
hi. i tried to learn hibernate and using some basic in my application. however, when i try to load an object, it gives a LazyInitializationException.

my code looks like

public static User LoadUser(User user)//user class current on contain userid
{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx = session.beginTransaction();
user = (User)session.load(User.class, user.getUserID());
tx.commit();
return user;
}

and it gives me exception
rg.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:56)
org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:158)

thanks for any help.


Top
 Profile  
 
 Post subject: in hbm file, set lazy=false
PostPosted: Sat Aug 12, 2006 5:46 am 
Newbie

Joined: Sat Aug 12, 2006 4:05 am
Posts: 3
you can set lazy=false in your hbm file, if any doubt for it. please attach your hbm file, we can point you the correct place.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 12, 2006 7:58 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Could be this line:

Code:
user = (User)session.load(User.class, user.getUserID());


There's no other piece of code that could throw an LIE (LazyInitializationException). If the user that you passed in to this method was lazily initialized (i.e. a member of a lazily initialized collection), then the user.getUserId() would not be able to be resolved if the session that loaded the user collection's owner was closed prior to this method call. If this is a constructed user object (for QBE for instance), then none of this code should produce the LIE. Did the stack trace identify the line of code? If so, which one?


Top
 Profile  
 
 Post subject: thanks
PostPosted: Sat Aug 12, 2006 4:40 pm 
Newbie

Joined: Thu Dec 01, 2005 5:58 pm
Posts: 10
thanks vividy.

now it is working fine. i need to read and understand "lazy".

thanks for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.