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....