@Entity
public class Person extends Model {
@OneToOne(cascade=CascadeType.ALL)
public Address address;
}@Entity
public class Address extends Model {
@OneToOne(cascade=CascadeType.ALL)
public Person person;
}
My object models contain each a "deleteAll()" member method.
In my Unit Test, @Before each test i do :
Person.deleteAll();
Address.deleteAll();
The error message i got on the Person.deleteAll() is :
Referential integrity constraint violation: "FK_ADDRESS_PERSON_1: PUBLIC.ADDRESS FOREIGN KEY(PERSON_ID) REFERENCES PUBLIC.PERSON(ID)"; SQL statement:
[error] delete from person where id=? and last_name=? and first_name=? and pseudonym=? and gender is null and date_of_birth is null and date_of_death is null and address_id is null [23503-158]
[error] at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
[error] at org.h2.message.DbException.get(DbException.java:169)
[error] at org.h2.message.DbException.get(DbException.java:146)
[error] at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:398)
[error] at org.h2.constraint.ConstraintReferential.checkRowRefTable(ConstraintReferential.java:415)
[error] at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:291)
[error] at org.h2.table.Table.fireConstraints(Table.java:861)
[error] at org.h2.table.Table.fireAfterRow(Table.java:878)
[error] at org.h2.command.dml.Delete.update(Delete.java:98)
To avoid this error i should change the "Person" model class :
...
@OneToOne(mappedBy="person",cascade=CascadeType.ALL)
public Address address;
...
But then i have problems in my Unit Test when getting the address via a person :
Person p = Person.findById(1);
assertNotNull(p.address);
The assertNotNull on person.address fails, person.address being null .
Laurent
--To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/pSQFqIMmHfkJ.
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.