Quote:
in Dept.hbm.xml
<set
name="emps"
lazy="false"
inverse="false"
cascade="all"
>
<key column="DEPTNO"/>
<one-to-many
class="com.yan.jdo.Emp"
/>
</set>
in Emp.hbm.xml
<many-to-one name="dept"
cascade="none"
update="true"
insert="true"
column="DEPTNO"/>
</class>
then add one Dept, and two Emp in it.
DeptDao deptDao = new DeptDao();
Dept dept = new Dept();
dept.setId(92);
dept.setDname("dgt");
Emp emp =null;
emp = new Emp();
emp.setId(new Short((short)448));
emp.setEname("567");
emp.setDept(dept);
Emp emp2 =null;
emp2 = new Emp();
emp2.setId(new Short((short)449));
emp2.setEname("566");
emp2.setDept(dept);
dept.getEmps().add(emp);
dept.getEmps().add(emp2);
deptDao.save(dept);
DAO Method is:
public class DeptDao extends HibernateDaoBase{
public void save(Dept dept){
try{
startTX();
session.save(dept);
commit();
}
catch(JDBCException e){
rollback();
Log.log("JDBCException:\n"+e.getSQLException());
}
catch(Exception e){
rollback();
Log.log(e.toString());
}
finally{
endTX();
}
}
}
but the sql shown is:
Hibernate: insert into SCOTT.DEPT (DNAME, LOC, DEPTNO) values (?, ?, ?)
Hibernate: update SCOTT.EMP set ENAME=?, JOB=?, MGR=?, HIREDATE=?, SAL=?, COMM=?, DEPTNO=? where EMPNO=?
Hibernate: update SCOTT.EMP set DEPTNO=? where EMPNO=?
result is the Dept saved into DB
but two emp not.
[/quote]