Skip to main content



      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 09:11 Go to next message
Eclipse UserFriend
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 10:25 Go to previous messageGo to next message
Eclipse UserFriend
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
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 10:59 Go to previous message
Eclipse UserFriend
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: Tue Jul 08 05:32:15 EDT 2025

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

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

Back to the top