When run against and Oracle database, what is the runtime type of the object that the following Spring Hibernate Template (Spring 2.5 and Hibernate 3.3.2GA) code returns whe
The class type of the object that hibernateTemplate.execute()
returns is indeed BigDecimal
. It turns out that the cause of the ClassCastException
is the cast of the return value of method doInHibernate()
:
(BigDecimal) query.uniqueResult();
Corrected code:
BigDecimal count = (BigDecimal) hibernateTemplate.execute(
new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
SQLQuery query = session.createSQLQuery(sql);
return query.uniqueResult();
}});
return count;