-->
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: how to ignore NonUniqueObjectException
PostPosted: Wed Apr 07, 2004 10:46 am 
Newbie

Joined: Wed Aug 27, 2003 2:43 am
Posts: 19
Location: Paris
Hello,

I use a type of session-per-request-with-detached-objects pattern in my layered application.

I have several situations where Collection's are retrieved from the database and these collections may contain duplicated information (same table row in different Java objects). I can't really help it, the application's domain object graph is not trivial and I can't lock() every transient object I ever retrieved every time I ask Hibernate to open a new Session and perform some operations.

So as there are duplicates in my Collection's, sometimes when I Session.saveOrUpdate() my objects, I get a NonUniqueObjectException.

So I would love Hibernate to simply ignore the duplicate objects and not throw exceptions. Is this possible, is this stupid, anybody met this situation and how did he/she solve it?


Thank you very much,
Adrian.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 8:11 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't really get your problem but I would say no.
Using optimistic locking help ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 11:32 am 
Newbie

Joined: Wed Aug 27, 2003 2:43 am
Posts: 19
Location: Paris
Hello, thanks for your answer.

I solved the problem by overriding the equals() and hashCode() methods of my domain objects in order for the various HashSet's (my Collections are in fact HashSets) to consider my objects equal() if their id's are equal and not if they are really identical Java objects.

That way two different Java objects with equal id's will never exist in the same HashSet.


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.