Hibernate query for multiple items in a collection

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

    SELECT item FROM Item item JOIN item.attributes attr 
        WHERE attr IN (:attrList) GROUP BY item
    

    and then in the Java code:

    List attrList = new ArrayList();
    attrList.add(..); // add as many attributes as needed
    ...// create a Query with the above string
    query.setParameter("attrList", attrList);
    

提交回复
热议问题