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

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



Back to the top