• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem saving Transient Parent and Children at once

 
Wagner-Otto Wutzke
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!

I�m having some problems with the persisting of transient objects with a collection of other transient child objects.
Maybe someone has seen this before and can open my eyes.

For the introduction, I�m using the Spring Framework and Hibernate 3.2 to persist objects with the following relationship. Really basic!



I have a HTML Form, where the users define the Workstep data and the same time the new PropertyValues (the children). This Form is sent to the Controller and there I try to persist the new Workstep and its PropertyValues.

Hier the code to persist the objects. Pretty simple.

in the controller:


in genericDao:



On calling the save method from the HibernateTemplate, I am getting the Exception:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [model.WorkstepPropertyValue#0].

I have already searched in this forum for a problem like this, but nobody has the same problem with transient parents and children.
On the Hibernate documentation it is also not really explained.

After that, I also tried not to cascade the save process and persist first the Parent object (Workstep) and then the children (PropertyValues) after in a service class, but I also didn�t work, because the last saved parent object had no ID at the time I wanted to persist its children. Also weird

Does anybody know, why this Exception and perhaps how to solve it???
I would be very very very thankful, because I�ve been trying to get it to work since a couple of days already.

Thanks in advance!

Wagner
Hamburg - Germany
[ January 17, 2008: Message edited by: Wagner-Otto Wutzke ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the Session is an object who's PK id is the same as the object that was detached that you are trying to save.

You will need to merge your detached object first before you can save, or you can evict the other object that is in the session that also has the same id value.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic