tags:

views:

30

answers:

1

is it possible to use PostgreSQL-like DISTINCT ON in EJB using named query?

o.fromDate,o.empLeaveMasterId,o.employeeInfoId, o.leavePurposeId ,o.toDate,o.createdByUserId,o.createDate,o.lastModifiedUserId,o.lastModifiedDate,o.isSystemRecord

The field describe above is my entity bean field and I want to get fromDate wise distinct record

Is it possible using namedquery ?

A: 

I don't see how this could be possible: JPQL offers a language that can be translated into SQL for any database, this obviously excludes database specific keywords.

My suggestion would be to use GROUP BY and subqueries instead, as suggested in the PostgreSQL documentation:

The DISTINCT ON clause is not part of the SQL standard and is sometimes considered bad style because of the potentially indeterminate nature of its results. With judicious use of GROUP BY and subqueries in FROM the construct can be avoided, but it is often the most convenient alternative.

Or use a native query if portability is not a concern.

Pascal Thivent