Hibernate query for multiple items in a collection

后端 未结 5 626
灰色年华
灰色年华 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 02:01

    Could you use aliasing to do this?

    Criteria itemCriteria = session.createCriteria(Item.class);
    itemCriteria.createAlias("itemAttributes", "ia1")
                .createAlias("itemAttributes", "ia2")
                .add(Restrictions.eq("ia1.name", "foo1"))
                .add(Restrictions.eq("ia1.attributeValue", "bar1")))
                .add(Restrictions.eq("ia2.name", "foo2"))
                .add(Restrictions.eq("ia2.attributeValue", "bar2")))
    

    Not sure how hibernate handles joining on the same property twice explicitly like that, maybe worth trying?

提交回复
热议问题