双向一对多关系如何配置 通过多的一方如何获取到一的一方的对象
5 回复
配置双向一对多pet set master后执行updateWith(pet,"master") 无法自动修改pet.masterId
@Table("tt_master")
public class Master {
@Id
private int id;
@Name
private String name;
@Many(target = Pet.class, field = "masterId")
private List<Pet> pets;
...
}
@Table("tt_pet")
public class Pet {
@Id
private int id;
@Name
private String name;
@Column
private int masterId;
@One(target=Master.class,field="masterId")
private Master master;
...
}
moudle
@At
public void testUpdateWithPet(){
Master master=new Master();
//master.setName("lee2");
//dao2.insert(master);
master=dao2.fetch(Master.class,3);
Pet pet=dao2.fetch(Pet.class,3);
pet.setName("doudou5");
pet.setMaster(master);
dao2.updateWith(pet,"master");
pet=dao2.fetch(Pet.class,4);
pet.setName("doudou6");
pet.setMaster(master);
dao2.updateWith(pet,"master");
}
添加回复
请先登陆