Replacing collections [message #385417] |
Fri, 30 January 2009 23:13 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
David J Rericha![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=david1260%40mchsi.com) Messages: 13 Registered: July 2009 |
Junior Member |
|
|
Dear members,
In my application, the user will edit a medical claim which has a
OneToMany association with diagnoses. Because the user can do all manner
of changes to the claim-diagnoses list, before saving the claim, I simply
clear the collection and insert the changed list. I am using
@PrivateOwned to perform the deletions. However, since the default
operation order is inserts, updates, and deletes, my inserted diagnoses
are deleted ( identity is a composite key of claim-id and diagnosis-id ).
I discovered UnitOfWork.shouldPerformDeletesFirst(), but I doesn't make
any difference. The claim-diagnoses (claimIcdms) are inserted and then
deleted:
em.getTransaction().begin();
UnitOfWork uow = (UnitOfWork)( (JpaEntityManager)em.getDelegate()
).getActiveSession( em );
uow.shouldPerformDeletesFirst();
em.persist( claim );
em.getTransaction().commit();
@Entity
@Table( name = "moms_claim" )
public class Claim extends MOMSEntity
{
...
@OneToMany(mappedBy = "claim", cascade = { ALL })
@OrderBy("sequence")
@PrivateOwned
private List<ClaimIcdm> claimIcdms = new ArrayList<ClaimIcdm>();
...
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03903 seconds