openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Praveen S Rao <pravr...@in.ibm.com>
Subject One-Many One-Sided Cascade Delete not working for Non-Nullable Foreign Key
Date Mon, 02 May 2011 16:34:52 GMT
Hi everyone,

I have a one-many one-sided relationship. While cascade persists works
properly, cascade delete does not work for a non-nullable foreign key column
because of the SQL ordering. For a nullable foreign key column, it is
working fine.
Basically, it tries to do this i guess:
1. Update the foreign key column in the child table to null (This is where
it is failing).
2. Delete the parent.
3. Delete the child.

My mappings are as follows :
public class Employee implements Serializable {
        ..
        ..
       
@OneToMany(targetEntity=Telephone.class,cascade=CascadeType.ALL,fetch=FetchType.EAGER)
        @ElementJoinColumn(name="EMPLOYEEID",
referencedColumnName="EMPLOYEEID")
        private List<Telephone> telephoneCollection = new
ArrayList<Telephone>();
        ..
        ..
}

There is nothing in Telephone class to reference the Employee since it is a
one-sided relationship.

Also as suggested by Dr. Pinaki Poddar (OpenJPA committer), i went through
this JIRA :
https://issues.apache.org/jira/browse/OPENJPA-39
and added <property name="openjpa.jdbc.SchemaFactory"
value="native(ForeignKeys=true)" /> in the persistence.xml. In the logs it
said that it has found out the actual foreign key, but, still it tried to
update the foreign key column in the child table to null and failed.

This is the trace snippet :
....
....
9203  TRACE  [main] openjpa.jdbc.SQL - <t 109577864, conn 2143846344>
executing prepstmnt 944453707 UPDATE MAPTEST.Telephone SET EMPLOYEEID = ?
WHERE EMPLOYEEID = ? [params=?, ?]
9219  TRACE  [main] openjpa.jdbc.SQL - <t 109577864, conn 2143846344> [16
ms] spent
9234  TRACE  [main] openjpa.jdbc.SQL - <t 109577864, conn 2143846344>
executing prepstmnt 322573114 DELETE FROM MAPTEST.Telephone WHERE
TELEPHONEID = ? [params=?]
9234  TRACE  [main] openjpa.jdbc.SQL - <t 109577864, conn 2143846344> [0 ms]
spent
9234  TRACE  [main] openjpa.jdbc.SQL - <t 109577864, conn 2143846344>
executing prepstmnt 1222265050 DELETE FROM MAPTEST.Employee WHERE EMPLOYEEID
= ? [params=?]
9250  TRACE  [main] openjpa.jdbc.SQL - <t 109577864, conn 2143846344> [16
ms] spent
....
....
Caused by: <openjpa-2.1.0-r422266:1071316 fatal store error>
org.apache.openjpa.util.ReferentialIntegrityException: DB2 SQL Error:
SQLCODE=-407, SQLSTATE=23502, SQLERRMC=TBSPACEID=2, TABLEID=9, COLNO=1,
DRIVER=3.57.110 {prepstmnt 944453707 UPDATE MAPTEST.Telephone SET EMPLOYEEID
= ? WHERE EMPLOYEEID = ? [params=?, ?]} [code=-407, state=23502]SQLCA
OUTPUT[Errp=SQLDFMT2, Errd=-2146041828, 28, 0, 0, -1800, 0]
DB2 SQL Error: SQLCODE=-407, SQLSTATE=23502, SQLERRMC=TBSPACEID=2,
TABLEID=9, COLNO=1, DRIVER=3.57.110

Am i missing out something here / is it a bug ? Please help. Thanks is
advance. 

--
View this message in context: http://openjpa.208410.n2.nabble.com/One-Many-One-Sided-Cascade-Delete-not-working-for-Non-Nullable-Foreign-Key-tp6324422p6324422.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message