Dear Members
I am very confused about the Count in HQL, I receive other values than the expected
I have read
16.16. Tips & Tricks where appear
Quote:
You can count the number of query results without returning them:
( (Integer) session.createQuery("select count(*) from ....").iterate().next() ).intValue()
Well I did the follow (
compile well)
Quote:
public Integer getCountAllEntidadByNombre(String nombre){
return ((Integer) this.sessionFactory.getCurrentSession().
createQuery("SELECT COUNT(e) FROM Entidad e WHERE e.nombresMaternoEntidad=:nombre").
setParameter("nombre", nombre.trim()).iterate().next()).intValue();
}
In my Test class I have this line
Quote:
Integer count = this.entidadDaoService.getCountAllEntidadByNombre("MANUEL ");
assertTrue("Debo ser igual o mayor que uno", count >=1 )
but I receive this error
Quote:
java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
at com.jordan.manuel.repository.hibernate.EntidadDaoImpl.getCountAllEntidadByNombre(EntidadDaoImpl.java:73)
I am confused, why or from where appear the
java.lang.Long ?, according with the API specification
intValue() said
Quote:
intValue
public int intValue()
Returns the value of this Integer as an int.
Specified by:
intValue in class Number
Returns:
the numeric value represented by this object after conversion to type int.
What is wrong?
Thanks in advanced