I have an object (BlogPost) that contains a collection of M: N elements (tags).
How to request an object (BlogPost), where at least one of its tags matches an element in a set of tags (user defined) with JPA2 (Hibernate).
findBlogPostWithAtLeastOneMatchingTag(Collection<Tag> tags){ ???? }
My main problem is that I really need to compare two tag collections: - BlogPost tag collection. - the collection I'm looking for
I tried Select p from Post p where p.tags in(:tags)
, but this did not work, since my message objects have more than one tag.
So what could I do instead?
My BlogPost object is as follows. It has several tags.
@Entity public class BlogPost{ @ManyToMany() @NotNull private Set<Tag> tags; @NotBlank private String content; ... }
The solution should not be JPQL, JPA-Criteria (not Hibernate-Criteria) would be fine too.
source share