strtus2 主外键关联 — 多表查询注解
例:Goods表 主键id
RuKu表 外键goodsId
Goods实体类:
@Id
@GeneratedValue(generator=”increment”)
@GenericGenerator(strategy=”increment”,name=”increment”)
private Integer id;
@OneToMany(targetEntity=RuKu.class,cascade=CascadeType.ALL)
@Fetch(FetchMode.JOIN)
//updatable=false很关键,如果没有它,在级联删除的时候就会报错(反转的问题)
@JoinColumn(name=”id”,updatable=false )
private Set sets = new HashSet();
RuKu实体类:
@ManyToOne(targetEntity = Goods.class)
@JoinColumn(name=”goodsId”,updatable=false)
private Goods goods;
public Goods getGoods() {
return goods;
}
public void setGoods(Goods goods) {
this.goods = goods;
}