-->
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: why is update when i want to add record??
PostPosted: Thu Mar 25, 2004 3:06 am 
Newbie

Joined: Sun Mar 14, 2004 1:37 am
Posts: 4
Location: china
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]

_________________
--*--


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 6:41 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Please read the FAQ and doc about unsaved-value

_________________
Emmanuel


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