Hibernation: Problem with HQL Row Count Subquery

I try to work with a subquery / subselect in HQL (Hibernate), but it does not work and throws an error ...

I want to know if there is an equivalent in HQL for something like this: ("plain" 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 tried to "translate" it from SQL to HQL, but it does not work ... it produces the following:

org.hibernate.hql.ast.QuerySyntaxException: unexpected token

Basically, I need to get the number of rows from the received subquery.

Any ideas?

+3
source share
2 answers

SQL- hibernate, POJO ( Projection, ).

POJO:

public class MyCount {
    private Integer count;

    public void setCount(Integer count) {
        this.count = count;
    }    

    public Integer getCount() {
        return count;
    }
}

Query:

Query query = getSession().createSQLQuery("select count(*) from dual");
    .addScalar("count")
    .setResultTransformer(Transformers.aliasToBean(MyCount.class));

MyCount count = (MyCount) query.uniqueResult();
0

- HQL .

0

All Articles