Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Why is a child of a OneToMany relation not updated? (works with TopLink)
Why is a child of a OneToMany relation not updated? (works with TopLink) [message #387375] Thu, 23 April 2009 13:11 Go to next message
Chris Cornelis is currently offline Chris Cornelis
Messages: 2
Registered: July 2009
Junior Member
Hi,

I'm in the process of migrating from TopLink to EclipseLink, but I ran
into a behavioral difference. When the parent of a OneToMany relation
(cascaded) is merged, the child object id is not updated with EclipseLink.

The testcode below works fine with TopLink, but the with EclipseLink the
last assertTrue() fails. Can anyone shed some light on this?

/************** TestChild **************/
@Entity
public class TestChild {
private static final long serialVersionUID = 4743558733184018876L;

private int id;

public TestChild() {
}

@Id @GeneratedValue @Column(name="id")
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}
}

/************** TestParent **************/
@Entity
@Table(name="testParent")
public class TestParent implements java.io.Serializable {
private static final long serialVersionUID = 7480710253587290253L;

private int id;
private Collection<TestChild> children;

public TestParent() {
this.children=null;
}

@Id @GeneratedValue @Column(name="id")
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

@OneToMany(cascade=ALL)
public Collection<TestChild> getChildren() {
return this.children;
}

public void setChildren(Collection<TestChild> children) {
this.children = children;
}
}

/************** UnitTest **************/
public class MigrationTest {
@Test
public void testTestParent() {
TestParent testParent = new TestParent();
EntityTransaction transaction = entityManager.getTransaction();
transaction.begin();
entityManager.persist(testParent);

TestChild testChild = new TestChild();
Collection<TestChild> children = new LinkedList<TestChild>();
children.add(testChild);
testParent.setChildren(children);

entityManager.merge(testParent);
entityManager.flush();
transaction.commit();


assertTrue(((TestChild)(testParent.getChildren().toArray()[0 ])).getId() !=
0);
assertTrue(testChild.getId() != 0); // ===> FAILS WITH ECLIPSELINK
}
}
Re: Why is a child of a OneToMany relation not updated? (works with TopLink) [message #387376 is a reply to message #387375] Thu, 23 April 2009 14:25 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The child id should definitely be getting assigned, I cannot see how this
could occur.

Enable logging on finest and include the log.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Re: Why is a child of a OneToMany relation not updated? (works with TopLink) [message #387377 is a reply to message #387376] Thu, 23 April 2009 14:59 Go to previous message
Gordon Yorke is currently offline Gordon Yorke
Messages: 77
Registered: July 2009
Member
The id is not assigned to that instance because that is a detached
instance. In TopLink the instance passed into the merge was previously
treated as the original and placed in the shared cache but because of an
behavioural expectation shift, spawned by JPA, on detached objects this
object is no longer treated as the shared cache instance and is therefore
not updated post commit.
--Gordon
Previous Topic:Refreshing objects with @Transient fields
Next Topic:JPA - How to use AVG while computing Calendar date.time differences
Goto Forum:
  


Current Time: Sat Sep 20 04:04:35 GMT 2014

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

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