-->
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.  [ 4 posts ] 
Author Message
 Post subject: Unable to insert children of Order
PostPosted: Tue Dec 13, 2005 1:26 pm 
Newbie

Joined: Mon Nov 28, 2005 11:15 am
Posts: 13
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 2:01 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Without seeing your code I can only offer a guess, but try removing the inverse="true" from your <bag> element. That attribute is used with bi-directional associations, but your LineItem class doesn't have an association to Order.

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 2:23 pm 
Newbie

Joined: Mon Nov 28, 2005 11:15 am
Posts: 13
nathanmoon wrote:
Without seeing your code I can only offer a guess, but try removing the inverse="true" from your <bag> element. That attribute is used with bi-directional associations, but your LineItem class doesn't have an association to Order.


Thanks for the reply. I had tried what you mention with a mapping backward. That did not fix my problem. I also do not follow why an update is being attempted in inserting the line items. Is using saveOrUpdate() the problem here?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 6:55 pm 
Newbie

Joined: Tue Dec 13, 2005 6:47 pm
Posts: 7
Make sure you have unsaved-value="any" set to composite-id.

Do you have batch update property of hibernate (hibernate.jdbc.batch_size) greater than 1.

Try with size 1


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

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.