SQL:
select * from A
inner join B where A.sn = B.cp_cn
一对多: A
private List<B> cpGbs;
@OneToMany(mappedBy = "a", fetch = FetchType.LAZY)
public List<B> getCpGbs() {
return cpGbs;
}
public void setCpGbs(List<B> cpGbs) {
this.cpGbs = cpGbs;
}
多对一:B
private A a;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CP_SN", referencedColumnName="sn", insertable = false, updatable = false)
public A getA() {
return a;
}
name = "CP_SN" -- 本表中的字段
referencedColumnName="sn" -- 关联表的字段