[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] OneToMany, FetchType.LAZY, CascadeType.ALL: Fails to persist child
|
Hi,
I am having a simple test-case which fails and I wonder if I am doing
anything wrong or if it's a bug. I have two entites which look like this:
@Entity
public class Foo {
@Id
@GeneratedValue
private Long id;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Collection<Bar> children = new ArrayList<Bar>();
/* ... */
}
@Entity
public class Bar {
@Id
@GeneratedValue
private Long id;
/* ... */
}
During my test I create a Foo instance, persist it and commit the
transaction. In the next step I lookup that entity, create a Bar
instance and add it to Foo's collection. Then I get a new transaction,
merge the Foo instance and commit the transaction. But the commit fails
with the following error:
[EL Warning]: UnitOfWork(7438914)--Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services -
2.0.0.v20091026-r5655): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.h2.jdbc.JdbcSQLException: NULL not allowed for
column CHILDREN_ID [90006-71]
Error Code: 90006
Call: INSERT INTO FOO_BAR (children_ID, Foo_ID) VALUES (?, ?)
bind => [null, 1]
Query: DataModifyQuery(sql="INSERT INTO FOO_BAR (children_ID, Foo_ID)
VALUES (?, ?)")
at
org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
If I change the FetchType from LAZY to EAGER, it works fine. Am I
missing something? I am using dynamic weaving and my entity-classes are
woven successfully. The EclipseLink version is 2.0.0.v20091026-r5655.
Thx in advance,
Oliver
p.s. I also posted to the forum:
http://www.eclipse.org/forums/index.php?t=msg&th=156875&start=0&S=39942ebc1ce02857be01b3dbb657edd2