简体   繁体   中英

How to retrieve selected items from a list of items?

In my application, user is able to select few items and see the details of all. I know that I can use the Criteria and using its Restrictions.disjunction(), I can define the "OR"; however, I need to retrieve the id of selected items from a list which makes it difficult to create the query using criteria.

Criteria cre = session.createCriteria(Category.class,"category");
cre.add(Restrictions.disjunction()) //?????
for(int i=0;i<selection.size();i++){
   cre.add(Restrictions.eq("category.items",selection.get(i)); 
}
....


@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@LazyCollection(LazyCollectionOption.FALSE)
public List<CategoryItem> getItems() {
    return this.items;
}

Another method is to send separate queries which I reckon thats an inefficient approach.

正如Ean所说,只需使用以下内容:

from Category c join c.items i where i.id in :yourList

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM