views:

49

answers:

1

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 doesn'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?

+1  A: 

Have you tried

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

See also:

axtavt
Ah! A two word answer and I couldn't find it anywhere. Thanks a ton!
Ritesh M Nayak