-->
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: SortedSet save problem
PostPosted: Mon Jan 10, 2005 7:29 am 
Newbie

Joined: Wed Dec 08, 2004 11:30 am
Posts: 8
Saving object employee with Sorted set as specified below

public class Employee {

/**
* @hibernate.set table="employee_machines" cascade="none" inverse="false" sort="com.mrt.vend.desktop.model.AssignedMachine"
* @hibernate.collection-key column="emd_emp_id"
* @hibernate.collection-composite-element class="com.mrt.vend.desktop.model.AssignedMachine"
*/

....
}

using code

session.saveOrUpdate(employee);

Hibernate tries to insert the existing row and falls over on database constraint key violation.
It should delete the row first then insert new one.

I tried
employee.setAssignedMachineList(null);
session.update(employee); employee.setAssignedMachineList(new list);
session.saveOrUpdate(dbData);

It does delete row and does not insert new one. Does anybody know how to make it working ?

Regards

Jerzy


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 10, 2005 7:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Employee e = session.load(Employee.class, "1");
employee.setAssignedMachineList(new list);
session.close()


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 10, 2005 8:37 am 
Newbie

Joined: Wed Dec 08, 2004 11:30 am
Posts: 8
It does not work correctly , it tries to insert existing rows. Ordinary set first does row delete then insert, here we have insert only without a delete.
Reseting list does not help. It know it is possible to do it in 2 transactions, first set the list to null , commit, set new list , commit again, I do not see other way.

michael wrote:
Employee e = session.load(Employee.class, "1");
employee.setAssignedMachineList(new list);
session.close()


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 14, 2005 12:11 pm 
Newbie

Joined: Sat Jan 08, 2005 3:40 pm
Posts: 7
Location: New York
I noticed a similar problem. I have to set to null or empty set, commit, then set with new values. I'm experimenting with different equals() and hashCode() implementations to see if that helps.

-S


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 14, 2005 12:23 pm 
Newbie

Joined: Sat Jan 08, 2005 3:40 pm
Posts: 7
Location: New York
sskinner wrote:
I noticed a similar problem. I have to set to null or empty set, commit, then set with new values. I'm experimenting with different equals() and hashCode() implementations to see if that helps.

-S


I noticed that it only seems to happen with composite element mappings. Also may have found a bug. If I call session.flush() within a transaction I get duplicate values on the composite.

-S


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.