I had the same problem working with hibernate 3.0.5 and MySQL 5 but I used the following code as a workaround:
Code:
Session session = sessionFactory.getCurrentSession();
SQLQuery q = session.createSQLQuery("select sum(u.visitas) as total "
+ "from estadisticasVisitasAUsuario u "
+ "where u.idUsuario = :idUsuario");
q.setInteger("idUsuario", idUsuario);
q.addScalar("total",Hibernate.LONG);
Object o = q.uniqueResult();
return ((Long) o).longValue();
Mapping conf:
Code:
<class name="EstadisticasVisitasAUsuario" table="estadisticasVisitasAUsuario">
<composite-id
name="pk"
class="data.dto.EstadisticasVisitasAUsuarioPK" >
<key-property name="idUsuario" column="idUsuario" type="integer" />
<key-property name="dia" column="dia" type="short"/>
<key-property name="mes" column="mes" type="short"/>
<key-property name="anio" column="anio" type="integer"/>
</composite-id>
<!-- Normal properties of a java class -->
<property name="visitas" column="visitas" type="long"></property>
</class>