File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Problem with JPQL: distinct Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Problem with JPQL: distinct" Watch "Problem with JPQL: distinct" New topic

Problem with JPQL: distinct

Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 206
Hi all,

I am writing simple JPQL. It seems to be not working. It's as

select new com.Names(distinct(cdtwk.cName)) from CSummaryByDateWeek cdtwk;

It says unexpected token: distinct.

When I take out the word distinct, it works fine.I know JPQL have distict keyword word, but then why not working??
Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 206
Hi all,

It worked as

select distinct new com.Names(cdtwk.cName) from CSummaryByDateWeek cdtwk;

fan lin

Joined: Jun 01, 2011
Posts: 1
hi, I do the same thing like you , but i don't understand how jpa know that which field need to distinct ?
My jpql is

select DISTINCT new model.Loggoldtmp( DATE_FORMAT(createdate, '%Y-%m-%d') as datevalue,year(createdate) as yearvalue,month(createdate) as monthvalue,quarter(createdate) as seasonvalue,dayofyear(createdate) as dayofyearvalue,dayofmonth(createdate) as dayofmonthvalue,dayofweek(createdate) as dayofweekvalue ,now() as createdate) "+
"from Loggold o";
I agree. Here's the link:
subject: Problem with JPQL: distinct
It's not a secret anymore!