Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] The problem with child.Parent(this) in a property access setter?

Hi,
I recently got bit by the scenario described here:
http://en.wikibooks.org/wiki/Java_Persistence/Mapping#Odd_behavior

I have A->B->C. Those entities are using property access. In the setters of the children, I am setting their parents, like this snippet from the class A:
 public void setChildren(List<B> children) {
   this.children = children;
   for (B b : children) {
     b.setParent(this);
   }
 }

When I try to remove a B (with the relationship severed), eclipselink tries to insert a duplicate A, throwing an exception.

This seems like a reasonable method, as the bidirectional relationship does not have to manually be maintained. Can anyone describe why this occurs so that I might avoid similar pitfalls in the future?

Thanks,
mike



Back to the top