[英]JPA superset using CriteriaQuery API
Given the following classes: 给定以下类别:
@Entity
public class Recipe {
@Id
@Column
private long id;
@ElementCollection
@CollectionTable(name = "recipe_ingredient", joinColumns = @JoinColumn(name = "id"))
private Set<String> ingredients;
...
}
How can I write the in JPA using the CriteriaQuery API the following: "Given a list of ingredients, return the Recipes that have at least all of the specified ingredients" 如何使用CriteriaQuery API在JPA中编写以下内容:“给出配料列表,返回至少包含所有指定配料的配方”
Offhand, it can be something like: 临时而言,它可能类似于:
criteria.add(Restrictions.in("recipe.ingredients", ingredients));
where ingredients
is a collection of ingredient strings. ingredients
是成分字符串的集合。 Add an alias if ingredients
throws you an exception. 如果
ingredients
抛出异常,请添加别名。
Warning: Criteria API is now deprecated . 警告:Criteria API现在已弃用 。
Otherwise, you can take a look here for an example. 否则,您可以在此处查看示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.