> List list = (List) getHibernateTemplate().findByNamedQueryAndNamedParam
> ("GetTransactionCount",
> parameterName, paramArgs);
> if (list.size() != 0) {
> count = (Integer) list.get(0);
> }
>
> This is okay when we use postgres, but when we use H2, I get a
> ClassCastException
> Caused by: java.lang.ClassCastException: java.lang.Long cannot be
> cast to java.lang.Integer
>
>
> I am guessing the return that H2 database sends is of the type Long.
> Is this how it is ? Is this a bug or is it how it is supposed to be in
> H2.
It's supposed to be a Long, but the documentation says 'Integer'. I
will change the documentation.
> I know I can typecast it to Long and the problem will be solved, but I
> was just concerned as we are trying to make minimal changes to the
> Java code.
Some databases return different data types depending on the actual
result (not sure about COUNT, but for SUM). Probably the most elegant
solution would be:
long count = ((Number) list.get(0)).longValue();
Regards,
Thomas