Hello,
Why when i retrieve an object who has <many-to-one> relationship with for e.g two parents and try to replicate it in another db. The foreign keys are assigned to null and I get the
Quote:
Try to insert null into a non-nullable
message.
For my case the child is ITEM and the parents are USERS and BID.
Anyone help?
Hibernate version:
3
Mapping documents:
ITEM :
<column name="APPROVED_BY_USER_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to User -->
<many-to-one
name="userBySellerId"
class="com.hibernate.User"
not-null="true"
fetch="join"
>
<column name="SELLER_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to Bid -->
<many-to-one
name="bid"
class="com.hibernate.Bid"
not-null="true"
fetch="join"
>
<column name="SUCCESSFUL_BID_ID" />
</many-to-one>
Full stack trace of any exception that occurs:
Hibernate: insert into ITEM (VERSION, NAME, DESCRIPTION, INITIAL_PRICE, INITIAL_PRICE_CURRENCY, RESERVE_PRICE, RESERVE_PRICE_CURRENCY, START_DATE, END_DATE, STATE, APPROVAL_DATETIME, CREATED, APPROVED_BY_USER_ID, SELLER_ID, SUCCESSFUL_BID_ID, ITEM_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
(util.JDBCExceptionReporter 71 ) SQL Error: -10, SQLState: 23000
(util.JDBCExceptionReporter 72 ) Try to insert null into a non-nullable column in statement [insert into ITEM (VERSION, NAME, DESCRIPTION, INITIAL_PRICE, INITIAL_PRICE_CURRENCY, RESERVE_PRICE, RESERVE_PRICE_CURRENCY, START_DATE, END_DATE, STATE, APPROVAL_DATETIME, CREATED, APPROVED_BY_USER_ID, SELLER_ID, SUCCESSFUL_BID_ID, ITEM_ID) values (0, 'Item Three', 'Don''t drive SUVs.', 10, 'USD', 10, 'USD', '2005-09-27 13:39:36.358', '1966-01-01 00:00:00.0', 'D', '1966-01-01 00:00:00.0', '2005-09-27 13:39:36.358', 1, NULL, NULL, 3)]
(def.AbstractFlushingEventListener 277 ) Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: could not insert: [com.hibernate.Item]
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1869)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2200)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at com.acc.testdatamgt.DependentObjects.load(DependentObjects.java:217)
at com.acc.testdatamgt.DBSubset.main(DBSubset.java:146)
Caused by: java.sql.SQLException: Try to insert null into a non-nullable column in statement [insert into ITEM (VERSION, NAME, DESCRIPTION, INITIAL_PRICE, INITIAL_PRICE_CURRENCY, RESERVE_PRICE, RESERVE_PRICE_CURRENCY, START_DATE, END_DATE, STATE, APPROVAL_DATETIME, CREATED, APPROVED_BY_USER_ID, SELLER_ID, SUCCESSFUL_BID_ID, ITEM_ID) values (0, 'Item Three', 'Don''t drive SUVs.', 10, 'USD', 10, 'USD', '2005-09-27 13:39:36.358', '1966-01-01 00:00:00.0', 'D', '1966-01-01 00:00:00.0', '2005-09-27 13:39:36.358', 1, NULL, NULL, 3)]
at org.hsqldb.Trace.getError(Unknown Source)
at org.hsqldb.Result.<init>(Unknown Source)
at org.hsqldb.jdbcConnection.executeHSQL(Unknown Source)
at org.hsqldb.jdbcConnection.execute(Unknown Source)
at org.hsqldb.jdbcStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbcStatement.executeUpdate(Unknown Source)
at org.hsqldb.jdbcPreparedStatement.executeUpdate(Unknown Source)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1853)
... 12 more
org.hibernate.exception.GenericJDBCException: could not insert: [com.hibernate.Item]
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1869)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2200)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at com.acc.testdatamgt.DependentObjects.load(DependentObjects.java:217)
at com.acc.testdatamgt.DBSubset.main(DBSubset.java:146)
Caused by: java.sql.SQLException: Try to insert null into a non-nullable column in statement [insert into ITEM (VERSION, NAME, DESCRIPTION, INITIAL_PRICE, INITIAL_PRICE_CURRENCY, RESERVE_PRICE, RESERVE_PRICE_CURRENCY, START_DATE, END_DATE, STATE, APPROVAL_DATETIME, CREATED, APPROVED_BY_USER_ID, SELLER_ID, SUCCESSFUL_BID_ID, ITEM_ID) values (0, 'Item Three', 'Don''t drive SUVs.', 10, 'USD', 10, 'USD', '2005-09-27 13:39:36.358', '1966-01-01 00:00:00.0', 'D', '1966-01-01 00:00:00.0', '2005-09-27 13:39:36.358', 1, NULL, NULL, 3)]
at org.hsqldb.Trace.getError(Unknown Source)
at org.hsqldb.Result.<init>(Unknown Source)
at org.hsqldb.jdbcConnection.executeHSQL(Unknown Source)
at org.hsqldb.jdbcConnection.execute(Unknown Source)
at org.hsqldb.jdbcStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbcStatement.executeUpdate(Unknown Source)
at org.hsqldb.jdbcPreparedStatement.executeUpdate(Unknown Source)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1853)
... 12 more
Exception in thread "main"
Name and version of the database you are using:
HSQLDB