Java – hibernate criteria API: filter by subset
•
Java
I have a class that contains a set of B's
I want to create a hibernate criteria to get the set of all a, where the BS set is a superset of a given set
for instance:
Suppose we have three class a objects
A1, where there is a group of BS = [B1, B2, B3] A2, setting = [B3, B4, B5] A3, B5]
Suppose I want all a so that its set contains [B3, B5] Then the results will be A2 and A3
I wish I knew myself Thank you in advance! Manuel
Solution
I solved it like this It's hard to know if it works, but once you see it, it's easy
B[] subset = new B[] {b3,b5}; DetachedCriteria.forClass(A.class).createAlias("bs","b"); for (B b : subset) { criteria.add(Restrictions.eq("b.id",b.getId())); }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码