-->
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: Lookup table mapping and NonUniqueObjectException
PostPosted: Thu Jul 22, 2004 11:23 am 
Beginner
Beginner

Joined: Tue Jun 22, 2004 3:16 pm
Posts: 35
In our application database, we have few lookup tables, such as State, AddressType, PhoneType, and so on. They are read only and pre-loaded. The problem I am having is that when I save objects, I get:

com.mytest.DAOException: net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: P, of class: com.mytest.AddressType

This happneded when I tried to save two objects, Person and Organization and the Address is the association. That means Person and Organization all have Address attribute. In one session, the Address has State and AddressType and they are the same record. According to Hibernate, it is not allowed.

Help?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 6:48 am 
Newbie

Joined: Tue Jul 27, 2004 6:35 am
Posts: 2
I feel your pain, we have had a lot of those issues as well. Maybe it is an application design floor on our part. Apples and Oranges.

It seems like Hibernate uses == to compare object references instead of equals() to compare object contents.

I wrote a little utility to scan an object graph and look for objects with different references, but are equal using equals() and pick one of n of those instances and do a reassign through the entire object graph so that only one unique instance exists. So before I do any save/saveOrUpdate I run this utility to update references. It takes around 40/50 ms for the first round and thereafter I get mostly 0-15 ms for the update to complete.

This does require your object to define it's own equals() method though.

Anyway this sorts out this nasty exception. If you want the source my mail is ri.so@webmail.co.za


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.