这question回答了相反的关系。我一直试图为以下模型提出Criteria Query:
@Entity
public class One {
@Id
private BigInteger supplierId;
@Column(name = "name")
String name;
...
}
@Entity
public class Many {
@Id
private BigInteger posId;
@ManyToOne
@JoinColumn(name = "column_name")
One one;
@Column(name = "description")
String description;
}
我无法改变模型。我最常以这种方式保持单向。我正在尝试针对以下情况提出Criteria Builder代码:
- 我将获得以下属性:nam
,desc
。我需要找到名称属性等于One
的所有nam
实体,并且这些实体具有相关的Many
实体,其描述属性等于desc
答案 0 :(得分:-2)
Criteria query = this.getSession().createCriteria(Many.class);
query = query.add(Restrictions.eq("one.name", nam));
query = query.add(Restrictions.eq("description", desc));
query.list();
这种方式不起作用?