Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » TopLink to EclipseLink migration(Different behavior for new objects in nested UnitOfWork)
TopLink to EclipseLink migration [message #959089] Fri, 26 October 2012 12:54 Go to next message
Peter Sterba is currently offline Peter SterbaFriend
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 Smile

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 #964643 is a reply to message #959089] Tue, 30 October 2012 17:30 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
I haven't looked over the code yet, but can you post which versions of TopLink this worked on, and what version of EclipseLink you are using? If the version of TopLink wasn't a later release, can you try it just narrow down when the behavior might have changed?

Best Regards,
Chris
Re: TopLink to EclipseLink migration [message #971851 is a reply to message #964643] Mon, 05 November 2012 06:46 Go to previous messageGo to next message
Peter Sterba is currently offline Peter SterbaFriend
Messages: 4
Registered: October 2012
Junior Member
Thank you for the reply.

This case was tested on TopLink 9.0.3 build 423. EclipseLink version is 2.4.0
If I remeber correctly we have encountered this same behavior when testing TopLink Essentials 9.1. My appology for not including the versions in first topic Rolling Eyes .

According to this reply on Nabble (//eclipse.1072660.n5.nabble.com/TopLink-to-EclipseLink-migration-tp155391p155450.html), it could be a bug. I have yet to verify this.

[Updated on: Mon, 05 November 2012 06:46]

Report message to a moderator

Re: TopLink to EclipseLink migration [message #973663 is a reply to message #959089] Tue, 06 November 2012 14:19 Go to previous messageGo to next message
Peter Sterba is currently offline Peter SterbaFriend
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 Go to previous message
Peter Sterba is currently offline Peter SterbaFriend
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

Previous Topic:Virtual entities and XMLMetadataSource
Next Topic:ValidationException for enum class
Goto Forum:
  


Current Time: Tue Apr 23 13:40:53 GMT 2024

Powered by FUDForum. Page generated in 0.02981 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top