I have a simple mapping of Order Has Line Items. The Line items table has a primary key of {ORDER_ID, PRODUCT_ID}. The ORDER_ID is the primary key of the W_ORDER table and has auto-increment set to true with the generator class as Native.
When attempting to insert a newly created order, the ORDER_ID key is not being propagated to the LINE_ITEM table's equivalent column. Any help is greately appreciated. Thanks in advance.
Hibernate version:3.0
Mapping documents:
<class name="Order" table="w_order"> <synchronize table="W_LINE_ITEM"/> <id name="id" column="ID" type="java.lang.Integer" > <generator class="native"> </generator> </id> <bag name="lineItems" fetch="join" lazy="false" inverse="true" cascade="all-delete-orphan"> <key> <column name="ORDER_ID"/> </key> <one-to-many class="LineItem"/> </bag> </class>
<class name="LineItem" table="W_LINE_ITEM"> <composite-id name="id" class="LineItemKey"> <key-property name="orderId" column="ORDER_ID"/> <key-property name="productId" column="PRODUCT_ID"/> </composite-id> <property name="quantity" type="java.lang.Integer" update="true" insert="true" column="QUANTITY" not-null="true" />
</class>
Full stack trace of any exception that occurs: Hibernate: select lineitem_.ORDER_ID, lineitem_.PRODUCT_ID, lineitem_.QUANTITY as QUANTITY3_ from W_LINE_ITEM lineitem_ where lineitem_.ORDER_ID=? and lineitem_.PRODUCT_ID=? Hibernate: select lineitem_.ORDER_ID, lineitem_.PRODUCT_ID, lineitem_.QUANTITY as QUANTITY3_ from W_LINE_ITEM lineitem_ where lineitem_.ORDER_ID=? and lineitem_.PRODUCT_ID=? Hibernate: insert into W_LINE_ITEM (QUANTITY, ORDER_ID, PRODUCT_ID) values (?, ?, ?) Hibernate: insert into W_LINE_ITEM (QUANTITY, ORDER_ID, PRODUCT_ID) values (?, ?, ?) Hibernate: insert into W_LINE_ITEM (QUANTITY, ORDER_ID, PRODUCT_ID) values (?, ?, ?) Hibernate: insert into W_LINE_ITEM (QUANTITY, ORDER_ID, PRODUCT_ID) values (?, ?, ?) Hibernate: insert into W_LINE_ITEM (QUANTITY, ORDER_ID, PRODUCT_ID) values (?, ?, ?) Hibernate: insert into W_LINE_ITEM (QUANTITY, ORDER_ID, PRODUCT_ID) values (?, ?, ?) Hibernate: insert into W_LINE_ITEM (QUANTITY, ORDER_ID, PRODUCT_ID) values (?, ?, ?) Hibernate: insert into W_LINE_ITEM (QUANTITY, ORDER_ID, PRODUCT_ID) values (?, ?, ?) Hibernate: insert into W_LINE_ITEM (QUANTITY, ORDER_ID, PRODUCT_ID) values (?, ?, ?) Hibernate: insert into W_LINE_ITEM (QUANTITY, ORDER_ID, PRODUCT_ID) values (?, ?, ?) 11:19:08,324 WARN JDBCExceptionReporter:71 - SQL Error: 1048, SQLState: 23000 11:19:08,324 ERROR JDBCExceptionReporter:72 - null, message from server: "Column 'ORDER_ID' cannot be null" 11:19:08,324 ERROR AbstractFlushingEventListener:277 - Could not synchronize database state with session org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update 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.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226) 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 webstore.test.dao.OrderDAOTest.testCreateUpdateDelete(OrderDAOTest.java:59) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) 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:478) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Caused by: java.sql.BatchUpdateException: null, message from server: "Column 'ORDER_ID' cannot be null" at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1469) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
Name and version of the database you are using:MySQL 4.1
|