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