gpt4 book ai didi

java - 多对一单向关系的条件查询

转载 作者:行者123 更新时间:2023-11-29 09:31:59 25 4
gpt4 key购买 nike

question回答相反的关系。我一直在尝试为以下模型提出标准查询:

@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 代码:-我将被赋予以下属性:namdesc。我需要找到名称属性等于 nam 的所有 One 实体,并且有一个相关的 Many 实体,其 description 属性等于desc

最佳答案

Criteria query = this.getSession().createCriteria(Many.class);
query = query.add(Restrictions.eq("one.name", nam));
query = query.add(Restrictions.eq("description", desc));
query.list();

这种方式行不通??

关于java - 多对一单向关系的条件查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30191840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com