@Table("pet")
public class Pet {
@Id
private int id;
@Column
private String name;
@Column
private int masterId;
@One(target = Master.class, field = "masterId")
public Master master;
public Master getMaster() {
return master;
}
public String toString() {
return "\nPet [id=" + id + ", name=" + name + ", masterId=" + masterId + ", master=" + master + "]\n";
}
@Table("master")
public class Master {
@Id
private int id;
@Column
private String name;
@Many(target = Pet.class, field = "id")
private List<Pet> pets;
我这样写的,然后测试了查询pet,发现并不能查询到master,得到的结果是
[
Pet [id=1, name=人类, masterId=1, master=null]
,
Pet [id=2, name=超人, masterId=2, master=null]
,
Pet [id=3, name=怪物, masterId=3, master=null]
]
一对一,该怎么配置,多对多呢?新人,求解