Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Strange issue in merging changes.

Hi,

 

We have been using Eclipselink 1.2.0 with Spring.

 

We have configured Spring transaction interceptor (Using @Transactional(readOnly=false)) to manage the transactions in our Service code.

 

Parent  {

      @OneToMany(mappedBy="parent", cascade={CascadeType.ALL},  fetch=FetchType.EAGER)

      @org.eclipse.persistence.annotations.PrivateOwned

protected List<Child> children = new ArrayList<Child>();

}

 

Child {

      @ManyToOne(cascade={CascadeType.REFRESH}) @JoinColumn(name="SOME_CHILD_ID")

      protected Parent parent;

}

 

Service {

                @Transactional (readOnly=false)

                public void serviceMethod (Parent parent){

 

                                parent.setData(“data”);

                                ……

                                ……

                                Parent merged = em.merge(parent);

 

                                // Here the merged parent has lost the changes i.e. data

}

}

 

However I am seeing a strange issue in merging the changes for an entity which has a child entity with OneToMany relation. The changes done to the entity are getting lost. When I debugged into EL code, I went inside merge code where changes are calculated for an entity, however in org.eclipse.persistence.internal.descriptors.ObjectBuilder class I find that when the OneToMany mapping is being merged in the method while traversing through the DatabaseMapping, it calls further to merge changes in the Child, the target entity instance i.e. child entity instance doesn’t contain the latest parent entity with the changes. Hence the changes of the parent are getting lost.

 

public void mergeIntoObject(Object target, boolean isUnInitialized, Object source, MergeManager mergeManager, boolean cascadeOnly, boolean isTargetCloneOfOriginal)

 

However if I remove CascadeType.REFRESH in the ManyToOne mapping inside Child it works fine. Also if I mark the service method as @Transactional (readOnly=true) it works fine either.

 

Is there anything wrong in the entity relationship setup?

 

Kindly let me know.

 

TIA,
Shashi


Back to the top