Hibernate query for multiple items in a collection

后端 未结 5 739
灰色年华
灰色年华 2021-02-14 01:24

I have a data model that looks something like this:

public class Item {
    private List attributes;
    // other stuff
}

public class Item         


        
5条回答
  •  孤城傲影
    2021-02-14 01:39

    I didn't test it, but this is how I should try to solve your problem if I would have to:

    Map map1 = new TreeMap();  
    map1.put("ia.name","foo1");  
    map1.put("ia.value","bar1");  
    Map map2 = new TreeMap();  
    map2.put("ia.name","foo2");  
    map2.put("ia.value","bar2");  
    return getSession().createCriteria(Item.class)
    .createAlias("itemAttributes", "ia")
    .add(Restrictions.and()
         .add(Restrictions.allEq(map1))
         .add(Restrictions.allEq(map2))
    )
    .list();
    

    Please, let me know if it worked. I think the same should work with or()...

提交回复
热议问题