-->
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: parent child problem
PostPosted: Tue Jan 03, 2012 11:46 pm 
Newbie

Joined: Tue Jan 03, 2012 10:33 pm
Posts: 1
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


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.