Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [eclipselink-users] Related entity in a one-to-many relationship not being updated

Actually I misspoke.  I am using merge. 

 

However, the good news is that I have fixed the problem.  Here’s what I _was_ doing

 

1. Application user interface submits information

2. Sent to the service tier as a Registration data transfer object (DTO)

3. Service tier creates a Registration domain object from the DTO

4. Data access tier “saves” the domain object

 

I changed step 3 above to first load the matching Registration object (if there is one) from the database and *then* transfer the data from the DTO onto it.  Now, when I “save” the Registration all the related entities (such as Approval) are getting “saved” as well.

 

Thanks for helping.

 

Sri

 

From: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of Christopher Delahunt
Sent: Monday, August 16, 2010 9:30 AM
To: EclipseLink User Discussions
Subject: Re: [eclipselink-users] Related entity in a one-to-many relationship not being updated

 

Hello Sri,

Persist cascades over all references, but will not pick up any changes to existing objects.  That means none of the changes to existing objects will be saved to the database.  Try using merge instead.

Best Regards,
Chris

On 16/08/2010 9:28 AM, Sri Sankaran wrote:

Chris:
  Sorry for the confusion in terminology.  
 
Issue #1:  What is deactivation
  Deactivation of an Approval -- for the purposes of this discussion -- simply means that a property of the Approval object is being toggled.  From Eclipselink's perspective is it just some change.  I am not removing an object from the collection.
 
Issue #2: What do I mean by save
  These are unmanaged objects and I am invoking persist.
 
Sri
 
-----Original Message-----
From: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of Christopher Delahunt
Sent: Monday, August 16, 2010 9:07 AM
To: EclipseLink User Discussions
Subject: Re: [eclipselink-users] Related entity in a one-to-many relationship not being updated
 
Hello Sri,
 
What do you mean by deactivate, are you removing the old one from the collection?  And can you describe what you mean by save? (ie are you merging serialized/detached objects, or working with managed objects).  
If you are working with detached objects and removing the old approval from the collection, you will also need to null out the Approval's registration reference and merge the old approval for the change to be picked up - merge will only cascade on objects in the collection, so there is no way to pick up the changes to the now unreferenced old approval.
 
Best Regards,
Chris
 
On 15/08/2010 11:38 PM, Sri Sankaran wrote:
  
Using Eclipselink 2.0.0
 
The setup goes something like this:
 
public class Registration {
  ..
  @OneToMany(mappedBy = "registration", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
  private Collection<Approval> approvals; }
 
Imagine now a registration with 1 approval.  Then the user adds a new one.  The business logic calls for the previous one to be deactivated and the new one be set active.
 
public void bizLogic(...) {
  // load registration from DB
  // append a new approval to approvals collection
  // deactivate the old approval in the collection.
  // save registration to the database.
}
 
Stepping through the code with the debugger, I can see that the necessary business logic steps are undertaken.  Then when I commit changes to the database (by saving the Registration), the following take place:
 
*       Changes to the Registration are persisted
*       A new approval is persisted
 
Conspicuous by its absence is an update of the first approval.
 
What step am I missing?  FWIW, setting the approvals collection to FetchType.EAGER make no difference.
 
Sri
 
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
  
    
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
 
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
  

Back to the top