关于一对多(学生和班级)的一个奇怪问题,很难理解
学生
班级
实体类(学生)
public class Student implements Serializable{
private Integer id;
private String name;
private ClassRoom roomid;
....
班级
public class ClassRoom implements java.io.Serializable{
private Integer id;
private String name;
private Set set=new HashSet ();
测试类:
public void testAA5(){
Student ss1=new Student();
ss1.setName("wang34");
Student ss2=new Student();
ss2.setName("wang46");
Set set=new HashSet();
set.add(ss1);
set.add(ss2);
HibernateUtil.beginTransaction();
Session session=HibernateUtil.getCurrentSession();
ClassRoom room=(ClassRoom)session.get(ClassRoom.class,new Integer(1));
room.setSet(set);
ss1.setRoomid(room);
ss2.setRoomid(room);
session.getTransaction().commit();
session.close();
}
这是我的测试类:测试出错了
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
...
Caused by: java.sql.BatchUpdateException: ORA-01407: 无法更新 ("SYSTEM"."STUDENT"."ROOMID") 为 NULL
...
发出一下sql语句:
Hibernate: insert into student (name, roomid, id) values (?, ?, ?)
Hibernate: insert into student (name, roomid, id) values (?, ?, ?)
Hibernate: update student set roomid=null where roomid=?
如果将配置文件里的inverse改为true或者将session.get(ClassRoom.class,new Integer(1));改为session.load(ClassRoom.class,new Integer(1));
程序就没有错了,请高手解释一下原因
我想问的是Hibernate: update student set roomid=null where roomid=?
为什么发出这样的语句,关键是roomid=null,为什么是null
[b]问题补充:[/b]
inverse=false的情况下将set改为load为什么程序也没有错了,这是什么原因