我有以下模特:
@Entity
@Table(name = "feature")
public class DbFeature {
@Id
@GeneratedValue
public Long id;
@ManyToOne
public DbProduct product;
}
@Entity
@Table(name = "product")
public class DbProduct {
@Id
@GeneratedValue
public Long id;
@OneToMany(mappedBy = "product")
public List<DbFeature> features;
}
如何制作Criteria查询哪些产品会返回所有没有功能的产品?
谢谢!
答案 0 :(得分:0)
试试这个。
Criteria criteria = session.createCriteria(DbProduct.class).createAlias("features", "feature", CriteriaSpecification.LEFT_JOIN).add(Restrictions.isNull("feature"));
注意:它没有经过测试。