gpt4 book ai didi

Java hibernate 使用 hibernate session 从 where 子句中的 OneToOne 关系获取实体

转载 作者:行者123 更新时间:2023-11-29 12:02:37 25 4
gpt4 key购买 nike

我有带有 OneToOne 注释的 java hibernate 实体,我的目标是通过其他 hibernate 实体获取实体。

@Entity
public class Pick {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int pid;

@OneToOne
private Match_soccer match;

@OneToOne
private Algo1 algo;

@Column(length = 100)
private String pick;

@Column(length = 5)
private double plimit;
.....

匹配实体:

@Entity
public class Match_soccer extends Match{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int mid;

private String status;
...

我的目标是使用 hibernate session 获取 match.status == null 的选择。使用 session.criteria 可以获得我想要的东西吗?

最佳答案

您可以按如下方式编写查询:

Query query = session.createQuery("from Pick as p JOIN fetch p.match where p.match.status is null");
List list = query.list();

此查询将导致所有 match.status 为 null 的选择。

关于Java hibernate 使用 hibernate session 从 where 子句中的 OneToOne 关系获取实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32122248/

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