Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Replacing collections
Replacing collections [message #385417] Fri, 30 January 2009 23:13 Go to next message
David J Rericha is currently offline David J Rericha
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>();
...
}
Re: Replacing collections [message #385422 is a reply to message #385417] Mon, 02 February 2009 13:24 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Having two objects with the same Id in the same transaction is a very bad
idea. You might try to merge() the changes in the object to allow an
update (or nothing if not changed) instead of a full delete and
re-insertion.

Otherwise you could remove everything, then flush() then re persist them.
Or use two separate transactions.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Previous Topic:OneToMany associations
Next Topic:JPA: order by length?
Goto Forum:
  


Current Time: Fri Oct 24 08:35:38 GMT 2014

Powered by FUDForum. Page generated in 0.03839 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software