如何在Hibernate中选择数组大小为0的对象?

如何在Hibernate中选择数组大小为0的对象?,hibernate,Hibernate,我正在使用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&

我正在使用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();
我想知道我是否可以做以下事情:

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();

我想从没有任何配方的prices中选择所有产品

您好,我尝试了您的解决方案,但我不推荐使用LEFT_JOIN,因此我将其替换为JoinType.LEFT_OUTER_JOIN,但我仍然获得所有产品。这个限制不起作用。session.createCriteriaProduct.class.createAliasprices,prices.createAliasprices,recipes,recipes,recipes,JoinType.LEFT_OUTER_JOIN.addRestrictions.isNullrecipes.id.setResultTransformerCriteriaSpecification.DISTINCT_ROOT_ENTITY.list;
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();