java - One to Many search using AND condition -


I have the following product that has many colors.

I want to find a product that contains at least red and green.

  product class string ID; & Lt; Color & gt; Colour's{}; Color class id color Please ignore syntax error   

I am able to use the following for search or condition.

  Criteria Criteria = Make-up (;); Criteria.createAlias ​​("color", "color"); & Lt; String & gt; ColorsList = New Linkedist (); ColorsList.add ("green"); ColorsList.add ("red"); The criteria.Ad (restriction. ("Color color", list of colors);   

The above will be given to those products that are red or green in their colors but in those products At least red and green.

Example

  Products: Red Green - Pass Products: Red Green Yellow - Pass Products: Red Yellow - Unsuccessful   

Thanks in advance.

It is the idea that we choose all the products with colors and Every good Count the foot, then the products with both colors should count 2 as the number of colors

  different color color = (product category) for different characters. CreateAlias ​​("color", "color") .add (restriction. Eq ("colorcurer", "red") .add (restriction. Eq ("color.color", "green") .Setprogication (projection group ("Id")) .add (restriction criteria criteria = create index () .add (subqueries.in ("id", colorCrit) .list ();   

Update :

There is one for H Is absolutely ibernate for this The last comment describes how to use it.

Comments