您的位置:首页 > Web前端

Hibernate中通过FetchProfile的方式实现动态数据获取

2016-07-27 10:12 465 查看
1.在Entity类中定义FetchProfile

@Entity(name = "Employee")
@FetchProfile(
name = "employee.projects",
fetchOverrides = {
@FetchProfile.FetchOverride(
entity = Employee.class,
association = "projects",
mode = FetchMode.JOIN
)
}
)

Hibernate中提供了org.hibernate.annotations.FetchProfile标注和org.hibernate.annotations.FetchProfile.FetchOverride标注。
定义FetchProfile需要提供名称和要设置的关联属性。

2.在Session中支持FetchProfile

session.enableFetchProfile( "employee.projects" );

Session支持对名为employee.projects的FetchProfile。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息