I have below code snippet where i am using hibernate query. It works fine. when i fire execute this code second
time query is not fired as it is picked from query cache
Code:
Session session = hibernateFactory.openSession();
Query employeeQuery=session.createQuery("from Employee where employeeId=1");//line 1
employeeQuery.setCacheable(true);
Employee employee1=(Employee)employeeQuery.uniqueResult();
session.close();
But as soon as i replace line1 in above code snippet with below line i get exception
Query employeeQuery=session.createSQLQuery("select * from Employee where employeeId=1");
Execption is
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at org.hibernate.type.TypeHelper.disassemble(TypeHelper.java:146)
at org.hibernate.cache.StandardQueryCache.put(StandardQueryCache.java:106)
at org.hibernate.loader.Loader.putResultInQueryCache(Loader.java:2434)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2321)
at org.hibernate.loader.Loader.list(Loader.java:2268)
Is query cache is not applicable for native queries?
i think Query cache is applicable for HQL not for Native SQL. But in hibernate documentation its not written anywhere. So just wondering am i missing anything here