开发者

Hibernate: How do I write the HQL for getting records of an entity without records for its identifying relation

I have Hibernate Objects defined as

Class SomeText{
  private Long textId;
  private Set<Tag> Tags = new HashSet<Tag>();

  @ManyToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE })
  @JoinTable(name = "text_tag_reln",
   joinColumns = { @JoinColumn(name = "textId") },
   inverseJoinColumns = { @JoinColumn(name = "tagId") })
    public Set<Tag> getTags() {
        return Tags;
    }
}

Class Tag{
  private long tagId;
}

I now want to get all those SomeText objects that do not have any Tags. I wrote the following HQL but it d开发者_开发技巧oesn't work.

select st from SomeText as st where st.Tags = null

What do I do to get these records. In the SQL world, I would have written a query which would get all distinct textIds from the text_tag_reln table and get all SomeText ids that weren't present in that set. How can I do this in HQL?


Have you tried

select st from SomeText as st where st.Tags is empty

See also:

  • Chapter 14. HQL: The Hibernate Query Language
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜