The hsqldb test tables are generated without any enforcement of
referential integrity or unique primary keys, whereas the Oracle test
tables enforce them. This throws up a few errors in the JUnit tests
running on Oracle. Here is the first one, in
BidirectionalAssocationTest:
ORA-02292: integrity constraint (SCOTT.BIDIR_B_FK_1) violated - child record found at
oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1980) at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2748)
at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:605
) at
org.apache.ojb.broker.accesslayer.JdbcAccess.executeDelete(JdbcAccess.java:147) at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.delete(PersistenceBrokerImpl.java:38
6) at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.delete(PersistenceBrokerImpl.java:32
6) at
org.apache.ojb.broker.BidirectionalAssociationTest.deleteAllA(BidirectionalAssociationTes
t.java:126) at
org.apache.ojb.broker.BidirectionalAssociationTest.tearDown(BidirectionalAssociationTest.
java:179)
You can reproduce this with hsqldb as follows:
1. build junit
2. build prepare-testdb
3. Edit target/test/OJB.script, change the definition of table BIDIR_B
to add FOREIGN KEY and REFERENCES clauses:
CREATE TABLE BIDIR_B(PK VARCHAR(48) PRIMARY KEY,FK_TO_A VARCHAR(48),CONSTRAINT
SYS_FK_3 FOREIGN KEY(FK_TO_A) REFERENCES BIDIR_A(PK))
4. build junit-no-compile-no-prepare
This gives the same exception:
[org.apache.ojb.broker.accesslayer.JdbcAccess] ERROR: SQLException during the
execution of the delete (for a org.apache.ojb.broker.BidirectionalAssociationObjectA):
Integrity constraint violation: 23000 Integrity constraint violation in statement
[DELETE FROM BIDIR_A WHERE pk = 'A1031758902566' ]
Analysis:
OJB was correctly trying to null out the foreign key field when the reference was set
to
null in BidirectionalAssociationTest.deleteAllA, but PersistentFieldPropertyImpl.set()
is
just ignoring null values so the foreign key field is not being nulled out before the
delete, hence the constraint violation.
I traced this to PersistentFieldPropertyImpl.set():
if (aValue != null)
{
try
{
m.invoke(anObject, args); /* Reflection method */
}
catch (Throwable t)
{
String msg = t.getClass().getName();
logProblem(anObject, aValue, msg);
throw new PersistenceBrokerException(t);
}
}
else
{
/* DaveC: *** Nothing happens if aValue is null ****
called with anObject = our instance of BidirectionalAssociationObjectB
with fkToA non-null, relatedA null, aValue = null, m = setFkToA
*/
}
}
else
{
String msg = "getWriteMethod returned null";
logProblem(anObject, aValue, msg);
throw new PersistenceBrokerException(msg);
}
A possible patch is:
RCS file:
/home/cvspublic/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/PersistentFieldProper
tyImpl.java,v
retrieving revision 1.4
diff -w -r1.4 PersistentFieldPropertyImpl.java
93c93
< if (aValue != null)
---
> if ((aValue != null) || !getType().isPrimitive())
But it's not clear to me what was intended to happen here and this
could have major side-effects.
It would be nice if the whole hsqldb test database could be generated with
referential integrity and unique primary keys enforced but I couldn't work out how to
get
Turbine to do that.
--
Best regards,
David
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>