I have two Hibernate Entities A and B.
There is a ManyToMany association between A and B.
public class A {
@ManyToMany(targetEntity=B.class)
@JoinTable(name = "AB",
joinColumns = @JoinColumn(name="A_FK"),
inverseJoinColumns = @JoinColumn(name="B_FK"))
private Set<B> collectionOfB = new HashSet<B>();
// ...
}
public class B {
// no reference to A
}
I have an array {b1, b2,… ,bn} of B elements.
I need to search all the A elements that are associated to ALL the B elements of the list above (all the elements of {b1, b2,… ,bn} should be in collectionOfB).
So I have to do something like this:
select * from A as a where {b1, b2,... ,bn} in a.collectionOfB
But this is not possible 🙁
Does anybody have an idea how to deal with this ?
Thanks
Kamran
After some investigation I found out that the easiest way to deal with my problem was to use native SQL through
session.createSQLQuery(sql).With:
where
myListOfBcriteria={b1, b2,... ,bn}.Perhaps it’s not very ‘nice’ but it works well 🙂
I hope this can help some one,
Kamran