-->
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: Problems with NonUniqueObjectException
PostPosted: Wed Sep 14, 2005 11:35 am 
Newbie

Joined: Tue Sep 13, 2005 6:07 pm
Posts: 4
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate Version : 3.02

I have two tables PD and DS, with the following structures

PD DS
Pd_id (pkey) DS_id (Pkey)
Col a Pd_id (FKey)
Col b Col x
Col c Col y

Now here are the steps I perform

1)I first select all rows from DS where Pd_id = “123” (say)
2)Now delete all these rows (if there are any rows found)
3)Now add rows in DS with PD_id = “123” (same as step 1). The primary key for DS is generated by Hibernate.

On step 3, I get NonUniqueObjectException “a different object with the same identifier value was already associated with the session”.
I understand that hibernate hasn’t generated the pkey yet, so does it thinks the deleted row and the newly inserted row are the same as they have the same F Key (123) and it’s the same transaction (bean managed)?
How do I get around this? I just want Hibernate to delete the old rows and insert new rows with the same F Key but obviously different PKeys.

Just FYI….
The class PD contains a hashset containing objects of type DS. Here is the sample code I use while inserting rows into DS.

while (its.hasNext()) {
DS ds = new DS();
ds.setColA((Long)its.next());
ds.setPD(pd);
dsSet.add(ds);
}
pd.setDS(dsSet);
sess.saveOrUpdate(pd);


thank you all....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 11:50 am 
Newbie

Joined: Tue Sep 13, 2005 6:07 pm
Posts: 4
The table structures again, since they are not well formatted in my earlier post

PD
Pd_id (pkey)
Col a
Col b
Col c

DS
DS_id (Pkey)
Pd_id (FKey)
Col x
Col y


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 12:02 pm 
Beginner
Beginner

Joined: Fri Jun 10, 2005 11:51 pm
Posts: 45
...i think u need to reconstruct your question to get more clearer because the quality reply u will receive depends on the clarity of the question you send. ;=)


Top
 Profile  
 
 Post subject: summarize the question
PostPosted: Wed Sep 14, 2005 12:15 pm 
Newbie

Joined: Tue Sep 13, 2005 6:07 pm
Posts: 4
Sure Jack... Here is the summary of the question

I am trying to delete some rows and then insert new ones (with the same Foreign key, but obviously different Pkey) in one transaction. The rows get deleted (I can see the sql), however when new rows are being added, I get the NonUniqueObjectException. What can I do to resolve this?


Here is the stacktrace

[9/13/05 17:49:20:667 EDT] 6a7f6a7f SystemErr R org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.dataobject.PD#187352]
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java)
at org.hibernate.exception.NestableRuntimeException.<init>(NestableRuntimeException.java:100)
at org.hibernate.NonUniqueObjectException.<init>(NonUniqueObjectException.java:22)
at org.hibernate.NonUniqueObjectException.<init>(NonUniqueObjectException.java:28)
at org.hibernate.engine.PersistenceContext.checkUniqueness(PersistenceContext.java:586)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:254)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:214)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:432)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:427)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 2:30 am 
Beginner
Beginner

Joined: Fri Jun 10, 2005 11:51 pm
Posts: 45
..i think you should fix your mapping...i think there is trouble in your mapping file :)


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.