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

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
>   


Back to the top