I have the following code:
Code:
SQLQuery sqlQuery = s.createSQLQuery("select 1");
sqlQuery.setCacheable(true);
Number num = (Number) sqlQuery.uniqueResult();
But I get the following exception:
Code:
Caused by: java.lang.ClassCastException: java.lang.Integer
at org.hibernate.cache.StandardQueryCache.put(StandardQueryCache.java:83)
at org.hibernate.loader.Loader.putResultInQueryCache(Loader.java:2187)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2138)
at org.hibernate.loader.Loader.list(Loader.java:2096)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1697)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:811)
at myClass.myMethod(MyClass.java:53)
I think it is a bug, but maybe I'm wrong. The code in StandardQueryCache.put() checks for returnTypes.length, and if it other than 1, it casts to Object[], and this causes the error. The returnTypes.length in this case is 0.
Thanks,
Viliam