person(一)与patient(多)
一对多修改操作的时候,不能把多的那方patient中的person_id外键当做一个属性去修改,一定要记住,这个是一个引用,是指向person中的某个对象的引用,不是一个独立属性,在修改的时候,只要从person中取出某个对象,然后用patient.setPerson(person),就是保存了这个对象的引用了
这样就可以将外键指向person.id为4的对象了
http://oracleabc-126-com.iteye.com/blog/954375
一对多修改操作的时候,不能把多的那方patient中的person_id外键当做一个属性去修改,一定要记住,这个是一个引用,是指向person中的某个对象的引用,不是一个独立属性,在修改的时候,只要从person中取出某个对象,然后用patient.setPerson(person),就是保存了这个对象的引用了
Patient patient = new Patient();
patient = (Patient)session.get(Patient.class,3);
Person person2 = (Person)session.get(Person.class, 4);
patient.setPerson(person2);
session.update(patient);
这样就可以将外键指向person.id为4的对象了
http://oracleabc-126-com.iteye.com/blog/954375