Carol.Kar
Carol.Kar

Reputation: 5345

Get distinct values via hibernate

I want to get distinct values by a parameter:

@Transactional
public List<data> getAllFromColumn(String identifier) {

    List<data> resultList = em.createQuery("SELECT DISTINCT p.market FROM data p", Data.class).getResultList();

    return resultList;
}

My problem is that this only returns me a NullPointerException. Any recommendations what is wrong, or what I can do differently?

I appreciate your answer!

Upvotes: 0

Views: 670

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269463

If HQL doesn't support select distinct (which it doesn't seem to according to the syntax), you can do this using group by:

SELECT p.market
FROM data p
GROUP BY p.market;

Upvotes: 1

Related Questions