我想问下,一对多时,一方set标签里的inverse属性设为faise时,一方和多方都可以控制吧?
Country country = new Country(2,"japan"); Province province1 = new Province(3,"j1"); Province province2 = new Province(4,"j2"); //country.getProvinces().add(province1); //country.getProvinces().add(province2); province1.setCountry(country); province2.setCountry(country); session.save(country); session.save(province1); session.save(province2);
对应结果
Hibernate: insert into test.country (cname, cid) values (?, ?) Hibernate: insert into test.province (pname, cid, pid) values (?, ?, ?) Hibernate: insert into test.province (pname, cid, pid) values (?, ?, ?)
Country country = new Country(2,"japan"); Province province1 = new Province(3,"j1"); Province province2 = new Province(4,"j2"); country.getProvinces().add(province1); country.getProvinces().add(province2); //province1.setCountry(country); //province2.setCountry(country); session.save(country); session.save(province1); session.save(province2);
对应结果
Hibernate: insert into test.country (cname, cid) values (?, ?) Hibernate: insert into test.province (pname, cid, pid) values (?, ?, ?) Hibernate: insert into test.province (pname, cid, pid) values (?, ?, ?) Hibernate: update test.province set cid=? where pid=? Hibernate: update test.province set cid=? where pid=?
数据库里结果都是