您的位置:首页 > 其它

hibernate对应关系

2015-07-01 16:43 357 查看
1.@ManyToOne

数据表中记录外键值。

receiver

/**
* 获取地区
* @return 地区
*/
@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@NotFound(action=NotFoundAction.IGNORE)
public Area getArea()
{
return area;
}


@NotFound(action=NotFoundAction.IGNORE),意思是找不到引用的外键数据时忽略。

cusomizationInfo

/**
* 获取发件人
*
* @return 发件人
*/
@JoinColumn(updatable = false)
@ManyToOne(fetch = FetchType.LAZY)
public Member getSender()
{
return sender;
}


member

/**
* 获取职业
*
* @return 返回 occupation
*/
@ManyToOne(fetch = FetchType.LAZY)
public Occupation getOccupation()
{
return occupation;
}


2.@ManyToMany

promotion(促销)

@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "xx_promotion_brand")
public Set<Brand> getBrands()
{
return brands;
}


member(会员)

/**
* 获取收藏商品
*
* @return 收藏商品
*/
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "xx_member_favorite_product")
@OrderBy("createDate desc")
public Set<Product> getFavoriteProducts()
{
return favoriteProducts;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: