1、如实体PdOrg对象中有users对象,数据库user表有字段DEL_FLAG(0:删除;1:未删除):
private List<User> users= new ArrayList<User>();
生成get、set方法:
@OneToMany(fetch=FetchType.LAZY, mappedBy="user")
@BatchSize(size=10)
@Where(clause="DEL_FLAG=1")
@OrderBy(clause="CREATED_DATE asc")
public List<User> getUsers() {
return this.user;
}
public void setUsers(List<User> user) {
this.user= user;
}
@BatchSize(size=10) //缓存数据大小:10条数据
@Where(clause="DEL_FLAG=1") //代表只取未删除的数据;
@OrderBy(clause="CREATED_DATE asc") //代表按创建时间正序排列
2、用一个列关联多个实体属性,比如举报维权,举报的对象可能是用户,悬赏,商品,订单
//举报对象(用户)
@OneToOne(cascade = { CascadeType. REFRESH }, fetch = FetchType.EAGER )
@JoinColumn(name = "gid", insertable = false, updatable = false)
@NotFound(action=NotFoundAction. IGNORE)
private UserInfo reporteder;
//举报对象(悬赏)
@OneToOne(cascade = { CascadeType. REFRESH }, fetch = FetchType.EAGER )
@JoinColumn(name = "gid", insertable = false, updatable = false)
@NotFound(action=NotFoundAction. IGNORE)
private Reward reward;
//举报对象(商品)
@OneToOne(cascade = { CascadeType. REFRESH }, fetch = FetchType.EAGER )
@JoinColumn(name = "gid", insertable = false, updatable = false)
@NotFound(action=NotFoundAction. IGNORE)
private Product product;
//举报对象(订单)
@OneToOne(cascade = { CascadeType. REFRESH }, fetch = FetchType.EAGER )
@JoinColumn(name = "gid", insertable = false, updatable = false)
@NotFound(action=NotFoundAction. IGNORE)
private Order order;