I have am curious as to whether hibernate can accomplish my goal with cascading="save-update"
I have a Parent and child relationship, 1 to many.
Parent class
pId
Set child
Child class
cId
Parent p
I am receiving information from a source and updating my database with it. If I get a new Parent, I do a save and it will save its information as well as the children's information.
From my source, I can receive new Parents ( which works fine ) or updates to the Parent and/or the children receiving deletions,additions and updates.
If I get a deletion, addition and update to children associated to a Parent,
will hibernate do all of this to the child table by calling
session.update(Parent).
The result I want is the new child added, old child deleted and existing child to have new information. I was told it could not do this so I wrote some other code and now i was told it could do this.
There is a foreign key from the child to the parent.
The code I have now gets all the children for the parent from the source and db, I compare them and add, delete or update as need be. I then try and do an update to the parent and I get an exception. I think hibernate is trying to insert the children in the db, but get a constraint violation.
Any help would be appreciated.
|