-->
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.  [ 2 posts ] 
Author Message
 Post subject: Unabe to insert Paranet and Chld. It is inserting only child
PostPosted: Fri Dec 10, 2004 3:38 am 
Newbie

Joined: Fri Dec 10, 2004 2:30 am
Posts: 1
Location: Chennai
Hibernate version:
Version 2.0
Mapping documents:
<class name="com.sony.to.DeptTO" table="va_dept">

<id name="id" column="dept_id" >
<generator class="assigned"/>
</id>
<property name="name" column="name"/>

<set name="employees" table="va_emp" inverse="true" cascade="all" >
<key column = "dept_id" />
<one-to-many class="com.sony.to.EmployeeTO" />
</set>
</class>

<class name="com.sony.to.EmployeeTO" table="va_emp">

<id name="id" column="emp_no" >
<generator class="assigned"/>
</id>
<property name="name" column="emp_name" insert="true"/>
<property name="age" column="age" insert="true"/>

<many-to-one name="dept" class="com.sony.to.DeptTO" column="dept_id" />
</class>
Code between sessionFactory.openSession() and session.close():
Inside my Controller
------------------------
public ModelAndView handleEmployee(HttpServletRequest request,
HttpServletResponse response)
throws ServletException {

System.out.println("Inside handleEmployee");
DeptTO deptTO = new DeptTO();
deptTO.setId(1);
deptTO.setName("Sony");

EmployeeTO employeeTO = new EmployeeTO();
employeeTO.setId(1);
employeeTO.setName("Rajaram");
employeeTO.setAge(33);
employeeTO.setDept(deptTO);
deptTO.getEmployees().add(employeeTO);
deptTO.getEmployees().add(employeeTO);
deptTO.getEmployees().add(employeeTO);
m_dept.addDept(deptTO);
return new ModelAndView("workrequestListView");
}


Hibernate Class
------------------
public class DeptHibernate extends HibernateDaoSupport implements Dept {


public void addDept(DeptTO dept) throws DataAccessException {

getHibernateTemplate().save(dept);
}
}
Full stack trace of any exception that occurs:

I am not getting any exception.

Name and version of the database you are using:

Oracle 8i

The generated SQL (show_sql=true):

Hibernate: insert into va_dept (name, dept_id) values (?, ?)
Hibernate: update va_emp set emp_name=?, age=?, dept_id=? where emp_no=?

<b> Here it supposed to do both insert.............i don't know how it is invoke update query. </b>

Debug level Hibernate log excerpt:

I have an Dept and Employee object. I am trying to create Dept along with Employees using cascade="All" attribute. But unfortunitaly it is inserting only into Dept not in Employee. When i am looking into the query the hibernate generates is insert (dept) and update (employee) queries. But it supposed to create both insert query. Please help me out in solving this.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 2:55 am 
Newbie

Joined: Tue Dec 14, 2004 2:36 am
Posts: 4
You are trying to insert the employee with same Id. Try inserting employee with different ID

_________________
Dheeraj Sambhar


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.