gpt4 book ai didi

java - JPA 查询集合中的 bean 字段

转载 作者:行者123 更新时间:2023-11-30 04:13:12 26 4
gpt4 key购买 nike

我有隔壁类(class)的关系:

public class Company {
. . .
@OneToMany(mappedBy = "company", fetch = FetchType.EAGER, cascade=CascadeType.PERSIST)
private Set<CompanySecUser> companySecUsers;
. . .
}
public class CompanySecUser{
. . .
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="USER_ID")
private User secUser;

@Column(name = "IS_READ")
private BigDecimal isRead;
. . .
}

现在如何在 JPA 中对 Company 实体编写查询以仅获取具有指定 secUser.id 且 isRead = 1 的公司?

最佳答案

select company from Company company 
join company.companySecUsers user
where user.id = <ID> and user.isRead = 1

关于java - JPA 查询集合中的 bean 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19096848/

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