i have a problem with hibernate; I want to get the row count of this named query:
Code:
select distinct table.a, table.b from MyTable table where table.a = :val
where a and b are primary key columns of MyTable.
So, as i usually do with sql, I tried
Code:
select count(*) from
(select distinct table.a, table.b from MyTable table
where table.a = :val)
but hibernate refuse to execute this query, saying :
org.hibernate.hql.ast.QuerySyntaxError: unexpected token: ( near line 3, column 46)
I tried a lot of tricks (as select count(distinct table.a, table.b). for example), but none did satisfy me. The only way to do that on hql seems something like :
Code:
Query myQuery = session.createQuery("select distinct table.a, table.b from MyTable table where table.a = :val").setParameter("val", "...");
int count = myQuery.list().size;
but i'm afraid hibernate map the whole list when getting its size, which may be huge, whereas i'm only interest by its size.
Hibernate version:
3.1
Name and version of the database you are using:
Oracle 9i