dimanche 28 juin 2015

HQL query to get min id

This query returns the number of places available for the same table. Of all the id table returned I need one with smaller IDs. The id of the table is a string.

String SQL_QUERY = "   FROM PostoDBWrapper p"
                +    " WHERE p.tavolo  in"
        + "                     (SELECT p.tavolo "
        + "                     FROM PostoDBWrapper p "
+ "                             WHERE p.disponibilita = true  "
+ "                             GROUP BY p.tavolo             "
+ "                             HAVING COUNT(p.tavolo) >= :posRichiesti)"
+ "                    AND p.disponibilita = true" ;


Query query = session.createQuery(SQL_QUERY);  
query.setParameter("posRichiesti",posRichiesti);  

Aucun commentaire:

Enregistrer un commentaire