简体   繁体   中英

JPQL to Select Distinct Strings from a List of Strings in a POJO

I have a Java class that has a field which is a list of strings. The elements in the list will vary between objects, but I need to determine a list of distinct values for the field. The Java class looks something like this:

public class POJO implements Serializable {

    @ElementCollection
    private List<String> listOfStrings;

}

JPA creates new table called POJO_listOfStrings, and I could run a SQL query like

SELECT DISTINCT string FROM dbo.POJO_listOfStrings

to get the information I need. I'm at a loss how to do this the correct way with JPQL. Things like "SELECT DISTINCT s FROM POJO.listOfStrings s" do not work. Any help is greatly appreciated.

Distinct on an entity object doesn't work on simple select, you need to specify the element in entity which you want to retrieve distinct.

Similar post in below link should give an insight to it. How do you create a Distinct query in HQL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM