给出示例表
table: acknowledgement
==============
id,post_id,user_id
table: post
==============
id,content
table: attachment
==============
id,post_id,name
以及
在我的课程中,得到了一个专栏
@OneToMany(fetch=FetchType.EAGER, targetEntity=attachment.class, cascade=CascadeType.ALL)
@JoinColumn(name = "post_id", referencedColumnName="id")
private Set<attachment> file=null;
当用户登录时,系统将拥有用户ID,因此我的NativeQuery将是
select *,case when p.id is null then false else true end as ack from post
left join acknowledgement a on p.id = a.post_id where a.user_id = :id
数据:
==================================
= id , content , acknowledgement =
==================================
= 1 , hello , true =
==================================
= 5 , hello 5 , false =
==================================
我的问题是
如何在这种情况下将本机查询转换为命名查询中的HQL?
是否可以使用上述一对多的注释来解决 时的情况?
注意:我使用的是hibernate 4.1.6 final