I'm trying to figure out the Hibernate way of querying a list of entities that may contain an entity within it. Since that's probably confusing i'll just explain the situation more clearly.
I have an Entity A class which has a OneToMany relationship with Entity B. Now given a specific Entity B I want to be able to find all Entity A objects which contain the Entity B object in their list.
In SQL this would look like:
Code:
select t1.* from entityA as t1 inner join entityA_entityB_map as t2 on t1.id = t2.entityA_id where t2.entityB_id=?;
or
Code:
select t1.* from entityA as t1 where t1.id in (select t2.entityA_id from entityA_entityB_map as t2 where entityB_id=?);
So what would the JPA/HQL equivalent look like? Or should I use something else?
Thanks for any help!