Can an EL
dev team member please
share thought on why this would be happening. This has come as a
critical issue
for us and we are struggling to get an alternative to make it work.
Regards,
Shashi
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
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