I am trying to work with a subquery/sub-select in HQL (Hibernate) but it doesn’t work and throws an error…
I wanna know if there is an equivalent in HQL to something like this: (“normal” SQL)
select count(Z) from (SELECT SUM(existencia), almacen, oficina, fila from re_tinventarioubicacion where inventorybranchto = 2 GROUP BY almacen, oficina, fila, estante, entrepano, casilla, precioetiqueta) as Z
I have tried to “translate” it from SQL to HQL, but it doesn’t work… it throws this:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token
Basically, I need to get the row count from the resulting subquery.
Any ideas?
You can use native SQL queries with hibernate but you’ll need a simple POJO to map the return value to (actually in this case you might try some of the built-in transformers or try setting a Projection, i’m not sure if it would work or not).
POJO return value:
Query: