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>
|
|