i am having issues saving my parent-child entites... here are my hbm files and piece of code that tries to save the entities.. i am using hibernate 3. the parent-child relation is bi-directional... i tried to read through chapter 21 on the topic from references but was unable to understand where i am going wrong.
any pointers will be greatly appreciated..
Header.hbm...
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="InvoiceHeader" table="trt_owner.SUPPLIER_INV_HDR">
<id name="id" type="long" column="ID" >
<generator class="sequence">
<param name="sequence">trt_owner.SUPPLIER_INV_HDR_S</param>
</generator>
</id>
<property name="invoiceNumber" column="INVOICE_NUMBER" type="string" />
<property name="invoiceDate" column="INVOICE_DATE" type="date" />
<set name="supplierInvoiceItems" order-by="ID" lazy="true" cascade="all-delete-orphan" inverse="true">
<key column="SUPPLIER_INVOICE_HDR_ID" />
<one-to-many class="InvoiceItem"/>
</set>
</class>
</hibernate-mapping>
Item.hbm....
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="InvoiceItem" table="trt_owner.SUPPLIER_INV_ITEM">
<id name="id" type="long" column="ID" >
<generator class="sequence">
<param name="sequence">trt_owner.SUPPLIER_INV_ITEM_S</param>
</generator>
</id>
<property name="labour" column="LABOUR" type="long" />
<property name="material" column="MATERIAL" type="long" />
<many-to-one name="supplierInvoiceHeader" column="SUPPLIER_INVOICE_HDR_ID" not-null="true" />
</class>
</hibernate-mapping>
Code..
Code:
Header parent = new Header();
Set<Item> children = SomeServiceClass.buildSetOfItems();
DaoClass.saveOrUpdate(parent); //attempting to save parent without children (this gets saved)
//.. above save method has transaction-attribute requires_new
parent.setItems(new HashSet<Item>());
for(Item i: children){
i.setHeader(parent);
parent.getItems().add(i);
}
DaoClass.saveOrUpdate(parent); //attempting to update parent with children (this fails)
//.. above call is again transactional "requires_new"
Exception encountered is...
Hibernate operation: could not insert: [SupplierInvoiceItem];
uncategorized SQLException for SQL [
insert into trt_owner.SUPPLIER_INV_ITEM
(LABOUR, MATERIAL, SUPPLIER_INVOICE_HDR_ID, ID)
values
(?, ?, ?, ?)
]; SQL state [null];
error code [17041];
Missing IN or OUT parameter at index:: 1;
nested exception is java.sql.SQLException: Missing IN or OUT parameter at index:: 1