给定的示例表
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?
是否可以使用上述一对多的注释来解决案例?
注意:我使用的是休眠 4.1.6 final