I have two hibernate entities User and Blog. User can be interested in multiple Tags. Blog can belong to multiple Tags. For a User, How do i find the Blogs which belong to the Tags the User is interested in?
I need something like
Select * from Blog where Blog.Tags IN User.Tags
except that SQL or HQL doesnt allow such comparisons in IN clause
A solution which im using currently is: 1. Generate a VIEW USER_BLOGS which is the cartesian product of the join tables USER_TAGS and BLOG_TAGS. 2. Define an Entity UserBlog for the View and use it to filter Blogs in the HQL query:
Select * from Blog where Blog.id IN (Select blog_id from UserBlog where user_id = "CurrentUser")
Im sure this is a common scenario. Is there a pure Hibernate or HQL solution for this?