-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: many-to-one and "not null" database constraint
PostPosted: Tue Sep 14, 2004 2:38 am 
Newbie

Joined: Fri Aug 29, 2003 4:36 am
Posts: 16
Location: Belgium
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 code
Code:
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.