Hibernate version:
2.1.6
Mapping documents:
Code:
class name="Flight" table="FGFLT" lazy="true">
<id name="id" type="long" column="SEQNBRFGH" unsaved-value="0">
<generator class="FlightHiloGenerator">
<param name="max_lo">2</param>
<param name="table">FLTSEQNBR</param>
<param name="column">NXTSEQNBR</param>
</generator>
</id>
<many-to-one name="connectionFlight"
class="Flight"
column="CONNBRFGH"
cascade="save-update"
/>
</class>
Class codeCode:
public class Flight implements Comparable, Serializable {
private Long id;
private Flight connectionFlight;
}
...
Flight f1 = new Flight();
Flight f2 = new Flight();
f1.setConnectionFlight(f2);
f2.setConnectionFlight(f1);
FlightDAO.makePersistent(f1);
...
Full stack trace of any exception that occurs:
java.sql.SQLException: [SQL0407] Null values not allowed in column or variable CONNBRFGH.
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:533)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:504)
at com.ibm.as400.access.AS400JDBCStatement.commonExecute(AS400JDBCStatement.java:710)
at com.ibm.as400.access.AS400JDBCPreparedStatement.executeUpdate(AS400JDBCPreparedStatement.java:1104)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:468)
... 20 more
net.sf.hibernate.JDBCException: could not insert: [aero.aviapartner.fis.operationalflight.server.domain.OperationalFlight#33]
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:478)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2371)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at aero.aviapartner.backend.CommandService.handleCommandMessage(CommandService.java:29)
at aero.aviapartner.managing.PostManager.send(PostManager.java:23)
at aero.aviapartner.fis.operationalflight.server.transport.OperationalFlightDTOTest.testCreateWithConnectionFlight(OperationalFlightDTOTest.java:131)
at java.lang.reflect.Method.invoke(Native Method)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
Caused by: java.sql.SQLException: [SQL0407]
Null values not allowed in column or variable CONNBRFGH.
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:533)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:504)
at com.ibm.as400.access.AS400JDBCStatement.commonExecute(AS400JDBCStatement.java:710)
at com.ibm.as400.access.AS400JDBCPreparedStatement.executeUpdate(AS400JDBCPreparedStatement.java:1104)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:468)
... 20 more
Name and version of the database you are using:
DB2400
ddl
create table FGFLT (
SEQNBRFGH BIGINT not null ,
CONNBRFGH BIGINT
not null
)
Two flights can be connected to each other, by the connectionFlight field. But the foreign key has a not null constraint in the database, although a flight must not have a connecting flight. In the (already existing) database, the absense of a connection flight results in a zero in that field.
In Hibernate, this currently gives me problems as it tries to insert a null in the absense of a connecting flight or when inserting a pair of two new flights.
Anyone a suggestion how I can solve my problem?