-->
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: How to avoid NonUniqueObjectException
PostPosted: Mon Aug 09, 2004 9:48 pm 
Beginner
Beginner

Joined: Thu Nov 06, 2003 10:04 pm
Posts: 22
Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

Debug level Hibernate log excerpt:

Hi,

I am trying to figure out a way to avoid getting the NonUniqueObjectException. Any help on this is appreciated. This is my situation.

I have an instance of a class A, A1, which I persist after users make changes to it using update(). But before I persist it, I want to find out the differences between this modified A1 and whats in the database for the same identifier as A1. This I need to do to do some change log for A1. But since I have to load the already persissted instance of A1 first, so that I can find differences between the persisted A1 and the modifed A1, when I do an update() on the modified A1, I get this NonUniqueObjectException (obvious because I am loading another instance from the db with the same identifier). My question is there any way to tell Hibernate or configure somewhere in the class A, to avoid this exception.

Thanks
Rama


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 2:25 am 
Regular
Regular

Joined: Mon Oct 06, 2003 7:17 am
Posts: 58
Location: Switzerland
Try to evict the unmodified instance A1 (session.evict(A1)) and then update the modified instance.

Reto


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 2:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
or use saveOrUpdateCopy()


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 3:30 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
gavin wrote:
or use saveOrUpdateCopy()

Pardon, but I think this should be added to FAQ. I have not seen any references to these two saveOrUpdateCopy methods, neither in Hibernate reference documentation nor in "Hibernate In Action". They are only in Hibernate API javadoc, but as rule nobody reads javadocs from start to end.

Thanks

_________________
Leonid Shlyapnikov


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 3:34 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
Now I must rethink my poll vote :)

_________________
Leonid Shlyapnikov


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.