不为空的条件子查询
我想将以下子查询转换为使用 hibernate 子查询:
getCurrentSession().createQuery("from Employee where id in (select adminId from Department where adminId is not null)")
.list();
Employee:
<前><代码>@ManyToOne @JoinColumn(name = "fk_department_id", nullable = true) 私人部门;部门:
@OneToMany(fetch = FetchType.EAGER) @JoinColumn(名称 = "fk_department_id") 私有集
员工 = new HashSet<员工>(0);
任何人都可以向我提供此转换的示例吗,因为我读了一些示例,但我仍然不知道如何做到这一点。
I want to convert the following subquery to use hibernate subquery:
getCurrentSession().createQuery("from Employee where id in (select adminId from Department where adminId is not null)")
.list();
Employee:
@ManyToOne @JoinColumn(name = "fk_department_id", nullable = true) private Department department;
Department:
@OneToMany(fetch = FetchType.EAGER) @JoinColumn(name = "fk_department_id") private Set<Employee> employees = new HashSet<Employee>(0);
Can anyone please provide me with an example of this convert, because i read some examples and i still cannot figure out how to do that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
setProjection
调用使子查询仅返回adminId
属性,而不是整个Department
实体。Subqueries.propertyIn
创建了一个限制:搜索员工的属性id
必须位于子查询返回的结果集中中。
The
setProjection
call makes the subquery return theadminId
property only instead of the wholeDepartment
entity. TheSubqueries.propertyIn
creates a restriction: the propertyid
of the searched employee must bein
the set of results returned by the subquery.