Hi,
The use case you have presented can be supported with some twists. Follow
the steps described below:
Approach A:
1. Remove all phones from Address, but remember them
2. flush() the Address.
3. Database will now assign identity to Address
4. Add the phones back and set each phone's identifier to the newly assigned
identifier of the Address
5. commit
The other approach B which is cleaner
1. Add a @PostPersist method to Address.java as follows
@PostPersist
public void postPersist() {
if (phones == null) return;
for (Phone phone : phones)
phone.setAddressId(this.getId());
}
2. commit()
Unfortunately Approach B does not work as expected with existing OpenJPA
because it prohibits Phone.addressId value to be reassigned during a flush
cycle as resulted from Address.postPersist() method.
I have added a fix to relax that prohibition under some circumstances but I
am concerned whether this relaxing of restriction will now allow other truly
invalid use cases those the original restriction was duly imposing.
--
View this message in context:
http://n2.nabble.com/OpenJPA---two-sided-relation-between-objects-Issue-tp687050p720837.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.