gpt4 book ai didi

java - JPA Hibernate 在@ElementCollection 上选择不同的并进行比较

转载 作者:行者123 更新时间:2023-11-29 05:01:34 25 4
gpt4 key购买 nike

我将 Hibernate 与 JpaRepositories 结合使用。

实体类的相关部分是:

@Entity
public class Person {
//.. id and other attributes

@Column(name = "function")
@ElementCollection
private Set<String> functions;

// .. getter setter
}

我需要将我的实体类从只有一个函数更改为能够处理多个函数。我的一个 DAO 中有一个搜索功能,可以将所有现有函数与一个字符串进行比较,希望找到已经定义的函数。

原始的 JPA 查询是:

select DISTINCT(p.function) from Person p where UPPER(p.function) like UPPER(:term) order by p.function

如何使用新的@ElementCollection 归档相同的结果?

最佳答案

您需要将集合加入Person,然后进行选择。试试这个查询:

select DISTINCT(f) from Person p join p.functions f where UPPER(f) like UPPER(:term) order by f

关于java - JPA Hibernate 在@ElementCollection 上选择不同的并进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31958612/

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