Hibernate version:2.1.3
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:postgres 8.0.0
The generated SQL (show_sql=true):select count(*) as x0_0_ from contacts contact0_ where (UserId=1893 )
I have a very simple count query. I have run the following :
Code:
String sql = "from Contact where UserId = 1893";
Query query = sess.createQuery(sql);
Long counter = (Long) query.uniqueResult();
Which correctly complains that it is not a unique result as there are two rows returned. To obtain the count I have tried to execute the following but it returns null from the uniqueResult().
Code:
String sql = "SELECT count(*) from Contact where UserId = 1893";
Query query = sess.createQuery(sql);
Long counter = (Long) query.uniqueResult();
The resultant sql below correctly returns a count of 2.
select count(*) as x0_0_ from contacts contact0_ where (UserId=1893 )
This seems so simple! Any idea what I am missing?
Thanks[/code]