Skip to main content

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

Also,

 

Figured out that, in spring, if a transaction is writable, i.e. readOnly=false, an early transaction is started on the current UoW. The code is

 

            if (!definition.isReadOnly() && !this.lazyDatabaseTransaction) {

                  // This is the magic bit. As with the existing Spring TopLink integration,

                  // begin an early transaction to force EclipseLink to get a JDBC Connection

                  // so that Spring can manage transactions with JDBC as well as EclipseLink.

                  UnitOfWork uow = (UnitOfWork) getSession(entityManager);

                  uow.beginEarlyTransaction();

            }

And it is writable, an early transaction is started and the changes done to the parent are lost during merge. I couldn’t figure out how this changes the behavior, but looks like it does.

 

Can somebody please throw some light on this?

 

Thanks,

Shashi

 

From: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of Shashikant Kale
Sent: Tuesday, July 27, 2010 2:34 PM
To: EclipseLink User Discussions
Subject: [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