[英]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";
我知道我可以使用Criteria并使用其Restrictions.disjunction()来定义“ OR”; however, I need to retrieve the id of selected items from a list which makes it difficult to create the query using criteria.
但是,我需要从列表中检索所选项目的ID,这使得很难使用条件创建查询。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.