[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.rt.eclipselink] Why is a child of a OneToMany relation not updated? (works with TopLink)
|
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
}
}