-->
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.  [ 5 posts ] 
Author Message
 Post subject: merge() refresh problem
PostPosted: Wed Aug 10, 2005 3:36 am 
Newbie

Joined: Tue Aug 09, 2005 12:35 pm
Posts: 3
Hi!
I have to use merge() instead of saveOrUpdate() because I've got a NonUniqueObjectException in one of my classes. My problem is that, the merge () did the update well in the database but after the second GET from the webserver I got back the old value of the changed property. Do another GET (refresh, etc.) I got the new value.

Is there any reason of this? Is there any method to refresh the object? I try session.refresh(obj) but it didn't help. My session code is the following:
Code:
Session s = HibernateUtil.getSession();
Transaction tx = s.beginTransaction();
f.setFePasswd(f.getNpasswd1());
try
{
    s.saveOrUpdate(f);
}   catch (NonUniqueObjectException nu1)
{
    s.merge(f);
}
s.flush();
tx.commit();
HibernateUtil.closeSession();


Hibernate version 3.0.5.

Thanks for answer!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 5:55 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't really understand your issue.
Not related, but you should not use a session if an exception has been raised.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 10:08 am 
Newbie

Joined: Tue Aug 09, 2005 12:35 pm
Posts: 3
emmanuel wrote:
I don't really understand your issue.
Not related, but you should not use a session if an exception has been raised.


Actually I can't figure out any other solution how to determinate which method I have to use. I try saveOrUpdate and if it isn't successful I try merge.

Any idea how can I detect NonUniqueObject before doing saveOrUpdate?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 12:38 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
When you know what you do with your objet graph, this never occurs.
If you don't want to bother, always use merge.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 4:20 am 
Newbie

Joined: Tue Aug 09, 2005 12:35 pm
Posts: 3
I added a listener class to my web.xml which closes the SessionFactory before undeploying the webapp and now I don't get NonUniqueObjectException anymore...


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