-->
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: Insertion in Parent and child table
PostPosted: Tue Mar 23, 2010 2:00 am 
Newbie

Joined: Wed Mar 17, 2010 7:23 am
Posts: 3
hi,

i am using hibernation, and i want to insert a parent and child record, my hbm code is as follows

<class name="com.ParentForm" table="PARENT">
<id name="pk_parent_id" column="pk_parent_id">
<generator class="sequence">
<param name="sequence">seq_parent</param>
</generator>
</id>
<bag name="childDet" cascade="all" >
<key column="parent_id" />
<one-to-many class="com.ChildForm"/>
</bag>
<property name="p_name" column="p_name" type="java.lang.String"/>
<property name="p_age" column="p_age" type="java.lang.String"/>

</class>

<class name="com.ChildForm" table="CHILD">
<id name="pk_child_id">
<generator class="sequence">
<param name="sequence">seq_child</param>
</generator>
</id>
<property name="c_name" column="c_name" type="java.lang.String"/>
<property name="c_age" column="c_age" type="java.lang.String"/>
</class>

then in the code,
org.hibernate.Transaction tx =null;
ParentForm pform = ParentForm(form);
int count = pform.getPName().length;
String result="Success";
String sqlResult=null;
try {
session = sessionFactory.openSession();
tx = session.beginTransaction();
for(int i =0 ; i< count ; i++) {
ChildForm cForm = new ChildForm();
// absDetChild.setAbstract_id(pkValue);
cForm.setCName((absForm.getCName())[i]);
cForm.setCAge((absForm.getCAge())[i]);

}//End For
session.save(absForm);
}catch (JDBCException e){
sqlResult = e.getCause().toString();
traceLogger.info("Debugging 3");
e.printStackTrace();
} finally {
try{
// session.save(pForm);
sqlResult ="Success";
session.flush();
try{
tx.commit();
}catch(Exception e){
e.printStackTrace();
}
session.close();
}catch(JDBCException e){
sqlResult = e.getCause().toString();
e.printStackTrace();
}
result=displayMessages(sqlResult);
traceLogger.info(":::::::result:::::::"+result);

the code which i have written is missing some important thing, could some one help, as the insertion in both the tables are not taking place....

Annu


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.