-->
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: Two Parent Tbl w/one child Collection - Child Insert Failure
PostPosted: Thu Dec 02, 2010 7:06 pm 
Beginner
Beginner

Joined: Thu May 18, 2006 2:58 pm
Posts: 28
Here's the case:
1. The insert of the data into the two parent tables never fails.
2. The insert of the child table data fails once in a while.

Here's the DB details:
Two Parent Tables:
* TRANSACTION (pk: ORDER_ID)
* INVOICE (pk: INVOICE_ID)

One Child Table:
* TRANSACTION_LINE (fk:ORDER_ID; fk: INVOICE_ID)

Here's the logic Description:
1. I create a new Transaction Object with a null Transaction Line Collection.
2. I create a new Invoice Object with a populated Transaction Line Collection.
3. I issue a hibernate session.save() on the Transaction first, then the Invoice second.

Problem: The result is that every once in a while, the children aren't saved.

The one-to-many relationships are bags with with inverse=true in the parent.

Any thoughts?
Could it be the null reference to the collection in the Transaction?

Here are some mappings:

Transaction.hbm.xml
<bag name="transactionLine" inverse="true" cascade="save-update">
<key foreign-key="FK_N_TRANSA_RELATION__N_TRANSA">
<column name="ORDER_ID" not-null="true" precision="22" scale="0"/>
</key>
<one-to-many entity-name="org.hibernate.com.model.TransactionLine"/>
</bag>

Invoice.hbm.xml
<bag name="transactionLine" inverse="true" cascade="save-update">
<key foreign-key="FK_N_TRANSA_LINE_INVOICE_ID">
<column name="INVOICE_ID" not-null="false" precision="22" scale="0" />
</key>
<one-to-many entity-name="org.hibernate.com.model.TransactionLine" />
</bag>

TransactionLine.hbm.xml
<many-to-one name="orderId" entity-name="org.hibernate.com.model.Transaction" cascade="none" foreign-key="FK_N_TRANSA_RELATION__N_TRANSA">
<column name="ORDER_ID" not-null="true" precision="22" scale="0"/>
</many-to-one>

<many-to-one name="invoiceId" not-null="true" entity-name="org.hibernate.com.model.Invoice" cascade="none" foreign-key="FK_N_TRANSA_LINE_INVOICE_ID">
<column name="INVOICE_ID" precision="22" scale="0"/>
</many-to-one>


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.