JPA Hibernate中使用@ElementCollection和compare进行select distinct

3

我正在使用JpaRepositories和Hibernate。

实体类的相关部分如下:

@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实现相同的结果?
1个回答

7

您需要将集合与Person连接,然后进行选择。请尝试使用以下查询:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接