TopLink to EclipseLink migration [message #959089] |
Fri, 26 October 2012 12:54 |
Peter Sterba Messages: 4 Registered: October 2012 |
Junior Member |
|
|
We are migrating about a dozen applications from TopLink to EclipseLink. The package renamer helps a lot, but we have experienced an different behavior in fallowing situation:
In One-To-Many relationships (e.g. Person-To-PhoneNumber ) we are manipulating the PhoneNumbers side via nested UnitOfWork acquired from Persons UnitOfWork. Updating already persisted PhoneNumbers works fine. But when we create a new PhoneNumber (via one nested UOW, and commit it to the parent UOW), and then if user decide to change this newly created PhoneNumber in the same transaction (we will create another nested UOW, edit the fields, and commit it to the parent UOW), the change will not propagate to the parent. In TopLink it will.
Is there a different behavior in working with new objects in EclipseLink than in TopLink?
Any suggestion is appreciated
I hope this example code will explain more. This kind of pattern is used many times in our applications:
public class TestExample {
public void runTest(Session session) {
//step1 - User tries to edit persisted Person object
Person person = (Person) session.readObject(Person.class);
UnitOfWork uow = session.acquireUnitOfWork();
Person personClone = (Person) uow.registerObject(person);
//step2 - User adds new PhoneNumber to person
addPhoneNumber(personClone, uow);
//step3 - User edits newly creted PhoneNumber
PhoneNumber phoneNumber = personClone.getPhoneNumbers().get(0);
UnitOfWork nestedUow = uow.acquireUnitOfWork();
PhoneNumber phoneNumberClone = (PhoneNumber) nestedUow.registerObject(phoneNumber);
phoneNumberClone.setValue(2000);
nestedUow.commit();
//step4 - compare difference idn TopLink and EcliseLink
//in TopLink the value will be 2000
//in EclipseLink the value will be still 1000
int value = personClone.getPhoneNumbers().get(0).getValue();
}
private void addPhoneNumber(Person personClone, UnitOfWork parentUow) {
UnitOfWork nestedUowInsert = parentUow.acquireUnitOfWork();
Person personCloneInsert = (Person) nestedUowInsert.registerObject(personClone);
PhoneNumber phoneNumber = new PhoneNumber();
phoneNumber.setPerson(personCloneInsert);
phoneNumber.setValue(1000);
phoneNumber.getPerson().getPhoneNumbers().add(0, phoneNumber);
nestedUowInsert.commit();
}
}
class Person {
private final ValueHolderInterface phoneNumbers = new ValueHolder();
public Vector<PhoneNumber> getPhoneNumbers() {
if (this.phoneNumbers.getValue() == null)
this.phoneNumbers.setValue(new Vector<PhoneNumber>());
return (Vector<PhoneNumber>) phoneNumbers.getValue();
}
}
class PhoneNumber {
private final ValueHolderInterface person = new ValueHolder();
private int value;
public void setPerson(Person person) {
this.person.setValue(person);
}
public Person getPerson() {
return (Person) person.getValue();
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
|
|
|
|
|
Re: TopLink to EclipseLink migration [message #973663 is a reply to message #959089] |
Tue, 06 November 2012 14:19 |
Peter Sterba Messages: 4 Registered: October 2012 |
Junior Member |
|
|
One step further...
If I assign an id to the new object (when creating in nested UOW), then it works as expected. Anyway it could be still a bug.
I did not do that in the example, because I tried to simulate the design of these old projects we are migrating. And those projects are expecting to have id == null until commit.
I did not find anything weird in changeSets before commit, but I might be not looking for the right thing. Fiddling with different ways how to register object in nested UOW did not helped me either (when registering persisted PhoneNumber as nestedUow.registerExistingObject and new PhoneNumber as nestedUow.registerNewObject results in loss of reference to Person in persisted record. Weird)
I have created small test project to reproduce this bug on DerbyDB, both for EclipseLink and TopLink. It can be downloaded here
Should I log a bug or what should I try next? Cheers
[Updated on: Tue, 06 November 2012 14:20] Report message to a moderator
|
|
|
Re: TopLink to EclipseLink migration [message #974816 is a reply to message #964643] |
Wed, 07 November 2012 10:56 |
Peter Sterba Messages: 4 Registered: October 2012 |
Junior Member |
|
|
Thanks for the reply Criss,
I have tried few versions of TopLink I have hands on. It worked on 9.0.3 and 9.0.4.8 but not on 10.1.3.0 and 10.1.3.3
It did worked on all versions (including EclipseLink) when I set an id !=null while creating new object. But those old applications I`m migrating are expecting to have id == null until commit.
[Updated on: Wed, 07 November 2012 10:58] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02981 seconds