-->
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.  [ 2 posts ] 
Author Message
 Post subject: session.lock and TransientObjectException
PostPosted: Mon Jan 19, 2004 2:38 pm 
Newbie

Joined: Sun Jan 18, 2004 7:47 am
Posts: 3
Hello

I try to use Session.lock to reassign an Object from a previous session.

"The lock() method allows the application to reassociate an unmodified object with a new session." from Manual 8.6

So I tried this:

Code:
public void run1() throws Exception {
   Session _session = HibernateSession.currentSession();
   Team _team = (Team) _session.load(Team.class, new Long(1));
   HibernateSession.closeSession();
   
   _session = HibernateSession.currentSession();
   _session.lock(_team, LockMode.NONE);
   //_team.getPlayers().iterator();
   
   HibernateSession.closeSession();
}


Team is loaded in the first Session and is unchanged. But Session.lock throws the following Exception:

Code:
net.sf.hibernate.TransientObjectException: attempted to lock a transient instance
   at net.sf.hibernate.impl.SessionImpl.lock(SessionImpl.java:1487)
   at example.test.LockTest.run1(LockTest.java:29)
   at example.test.LockTest.main(LockTest.java:41)


The API doc say's:
"Throw when the user passes a transient instance to a Session method that expects a persistent instance."

This is true, after closing the first Session, the object is transient.


What have I to do, to get a new session for the object Team??

Thanks
Daniel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2004 2:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Use a current Version of Hibernate (session.lock(object, LockMode.NONE)) is working since 2.1. only


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.