Hibernate version: 3.1.3
Hello,
I'm reading through the documentation and in Chapter 14 Tips and Tricks I see:
You can count the number of query results without actually returning them:
( (Integer) session.iterate("select count(*) from ....").next() ).intValue()
When I try this:
Code between sessionFactory.openSession() and session.close():
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
((Integer)session.iterate("select count(*) from Users where username = '" + username + "'").next() ).intValue();
It says: The method iterate(String) is undefined for the type Session.
My HibernateUtil class is a copy/paste from the one from Chapter 1, 1.2.5. Startup and helpers.
I also noticed that it is missing the 'find' method which is used in other examples.
Now;
1. I'm guessing that this is because I'm using org.apache.commons.dbcp.BasicDataSourceFactory as a factory. However I was not able to find a quick alternative to test this or documentation to verify it. Could one of you do this (confirm/deny I mean)?
2. There is another HibernateUtil class in the tomcat quickstart guide
http://sun.calstatela.edu/~cysun/docume ... start.html but the session returned by that one doesn't have those methods either (duh!). So point 1 is probably valid.
- Could someone please either confirm or deny 1.
- Is the hibernate util class in the example good enough to use for a project or are there documented alternatives? If so, could someone point me to the resource where I can learn about this?
- Is there another factory I can just use as a replacement for BDSF without having to change anything else?
Thank you and good night.