-->
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: Pattern for NonUniqueObjectException
PostPosted: Tue Nov 23, 2004 1:04 pm 
Newbie

Joined: Wed Sep 01, 2004 1:38 pm
Posts: 5
Location: Saint Paul, MN
Hibernate version: 2.1

Hibernate is working properly.. I'm looking for a pattern to apply in this case.

Situation: I have a service receiving a transient, updated copy of an object called Host. If certain fields are changed on the Host then there are dependent fields on other objects that will be updated to reflect the change**. Obviously determining whether or not fields have changed necessitates loading the 'actual' copy and comparing the fields before saving the new version. In order to prevent a NonUniqueObjectException from being thrown when the transient copy is being saved, the 'actual' copy is evicted from the session after examining its elements.

This works on a small scale, but is very fragile as the number of conditions and side effects increase. What did technically work, and seems to be safer, is flushing/cleaning the session before calling update on the transient Host object. However, that is less efficient and doesn't seem ideal either.

Is there a recognized pattern for handling incoming transient objects and making sure this conflict doesn't occur?

Thank you for any ideas..

**Copious amounts of business logic and caching should be assumed, which precludes triggers handling the side effects on the db side.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 2:32 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
Obviously determining whether or not fields have changed necessitates loading the 'actual' copy and comparing the fields before saving the new version


select-before-update in the mapping file may help you ;)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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.