The usual way I've done this is as you describe: do a select count(*) and then convert to boolean in code doing a > 0.
e.g.
Code:
boolean booleanResult = ( (Long) session.createQuery("select count(*) from ....").iterate().next() ).longValue() > 0;
BTW I don't know what is meant by <sql-select>: is this something specific to your programming environment?
Using a HQL query it is possible to construct an object in the select clause.
http://www.hibernate.org/hib_docs/v3/re ... hql-select - has more details on what could go in the select clause.
So you could have a custom java class that takes the result of the count(*) and coverts it to boolean.
e.g.
Code:
public class CountInfo
{
public final boolean result;
public CountInfo(long count)
{
result = count > 0;
}
}
then in the Hibernate query:
Code:
Query query = session.createQuery("select new CountInfo(count(*))
from ..."); // TODO: fill in rest of HQL query
List<CountInfo> result = (List<CountInfo>)query.list();
boolean booleanResult = result.iterator().next().result;
However, I don't think this is a better that doing.
So - to answer your question: No I don't think there is a better way to do this.
At least I can't think of one!