我正在使用Hibernate,我有类似的东西:
public class Product{
private Integer id;
private List<Price> prices;
// getters and setters
}
public class Price{
private Integer id;
private Double price;
private Product product;
private List<Recipe> recipes;
// getters and setters
}
public class Recipe{
private Integer q;
//getters and setters
}
我想知道我是否可以做类似的事情:
List<Product> products = session.createQuery(
"select product from Price p"
+ " inner join p.recipes where p.recipes = null ").list();
我想从没有任何食谱的价格中选择所有产品
答案 0 :(得分:0)
session.createCriteria(Product.class).createAlias("prices", "prices")
.createAlias("prices.recipes", "recipes", Criteria.LEFT_JOIN)
.add(Restrictions.isNull("recipes.id"))
.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY).list();