-->
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.  [ 3 posts ] 
Author Message
 Post subject: Error using long term sessions
PostPosted: Wed Aug 10, 2005 11:51 am 
Newbie

Joined: Wed May 04, 2005 9:34 am
Posts: 16
Location: Germany
Hi,

i have the following problem. I use a hibernate-session to load an object (i.e. the object of a user that enters my web-application). For this object i have lazy-fetching activated so i keep the session alive to be able to fetch joined objects later. Then i store that object in a http-session.

At some stage in my application i make a change to that object (i.e. i change the password of the user) and want to save it. Therefore i use the still alive session that i used to load the object and get an error like this:

"a different object with the same identifier is allready ascouciated with the session"

How can i avoid it. Do i have to open different sessions, one for saving objects and one for loading them? Or is there something else i can do to avoid this error?

Any help would be much appreciated
Christoph

Hibernate 3.0.5
MySQL 4.1.2


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 12:46 pm 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
You really don't want to keep Hibernate sessions around for any longer then the request. So yes, you want to get the object in one session, then save it in another later.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 1:28 pm 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
hibernate garanties object-identity for a session-life-time.
I don't know your code, but if you load an object from session and some requests later you change and save it, you have to use the same object-instance as loaded.
Otherwise you first have to load it again, perferm your changes and then save it (using saveOrUpdate)!

It's no nead to use one session for loading and another for saving!

And remember to disconnect/connect the session!

HiH
curio


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