SikaMika kirjoitti:Päivän nörttikysymyksen aika.
Jos SQL-lause kuuluu: "SELECT DISTINCT productType FROM Product"
niin kuinka se kuuluu JPQL-lauseena?
Käytän kiertotienä SQL-kielistä nativeQuerya, mutta kiinnostaisi vastaus tuohon silti. Ei pitäisi olla kovin hankala, mutku ei keksi eikä mistään löydy vastausta.
Löytyy löytyy.
Se mitä haluat tehdä on projektio entiteetistä, eli ottaa vain yhden attribuutin.
SELECT DISTINCT prod.productType FROM Product prod
Kts. esim.
http://www.objectdb.com/java/jpa/query/ ... T_DISTINCT
Queries that use projection may return duplicate results. For example, the following query may return the same currency more than once:
SELECT c.currency FROM Country AS c WHERE c.name LIKE 'I%'
Both Italy and Ireland (whose name starts with 'I') use Euro as their currency. Therefore, the query result list contains "Euro" more than once.
Duplicate results can be eliminated easily in JPQL by using the DISTINCT keyword:
SELECT DISTINCT c.currency FROM Country AS c WHERE c.name LIKE 'I%'
The only difference between SELECT and SELECT DISTINCT is that the later filters duplicate results. Filtering duplicate results might have some effect on performance, depending on the size of the query result list and other factors.