Hi ,
I have 3 tables (employee, department,allowances) where in all 3 are related. I have written a join query to retrieve data. Its running fine, till i implement query based caching on the specific query - meaning when i set the tag use_query_cache as true and call setCacheAble(true), that time the code breaks -- so can joins' results be query cached and if yes then why is my query breaking when i try to implement .setCacheAble(true)
Hibernate version: hibernate3.0
Mapping documents: <hibernate-mapping default-access="property">
<class name="test.uscc.Employee" table="employee">
<id name="empno" length="10">
<column name="empno" not-null="false" />
</id>
<property name="empname" type="string" length="20"/>
<property name="deptno" type="integer" length="10"/>
<property name="salary" type="integer" length="10"/>
</class></hibernate-mapping>
Code between sessionFactory.openSession() and session.close():SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
System.out.println("dddddddddddddddddd"+sessionFactory);
Session session = sessionFactory.getCurrentSession();
System.out.println("wwwwwwwwwwwwwwwwwww"+session);
Transaction tx = session.beginTransaction();
int BASIC_PAY = 5000;
String sql = "SELECT employee.empname, employee.salary, department.dname FROM employee " + "JOIN department " + "on employee.empno = department.empno " + "WHERE " + "sysdate() >= employee.effdate and employee.expdate > sysdate() " + "and " + "employee.salary in (select al.salary from allowances al " + "where al.basicpay= :BASIC_PAY)" ; [b] List result = session.createSQLQuery(sql) .setCacheable(true) .setParameter("BASIC_PAY", BASIC_PAY) .list();
System.out.println("****The output got is******"+result.toString());
int h = result.size();
System.out.println("size is:::::"+h);
session.disconnect();
Statistics stats = sessionFactory.getStatistics();
System.out.println("stats "+stats);
System.out.println("******stats.getQueryCacheHitCount()"+stats.getQueryCacheHitCount());
double queryCacheHitCount = stats.getQueryCacheHitCount();
System.out.println("******stats.getQueryCacheMissCount()"+stats.getQueryCacheMissCount());
double queryCacheMissCount = stats.getQueryCacheMissCount();
double queryCacheHitRatio =
queryCacheHitCount / (queryCacheHitCount + queryCacheMissCount);
System.out.println("Query Hit ratio:" + queryCacheHitRatio);
EntityStatistics entityStats =
stats.getEntityStatistics( Employee.class.getName() );
long changes =
entityStats.getInsertCount()
+ entityStats.getUpdateCount()
+ entityStats.getDeleteCount();
System.out.println(Employee.class.getName() + " changed " + changes + "times" );[/b]
Full stack trace of any exception that occurs:1:18:35,706 INFO UpdateTimestampsCache: starting update timestamps cache at region: org.hibernate.cache.UpdateTimestampsCache
21:18:35,706 WARN EhCacheProvider: Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults.
21:18:35,726 INFO StandardQueryCache: starting query cache at region: org.hibernate.cache.StandardQueryCache
21:18:35,726 WARN EhCacheProvider: Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.
ddddddddddddddddddorg.hibernate.impl.SessionFactoryImpl@d5eb7
wwwwwwwwwwwwwwwwwwwSessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[]])
Hibernate: SELECT employee.empname, employee.salary, department.dname FROM employee JOIN department on employee.empno = department.empno WHERE sysdate() >= employee.effdate and employee.expdate > sysdate() and employee.salary in (select al.salary from allowances al where al.basicpay= ?)
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at org.hibernate.type.TypeFactory.disassemble(TypeFactory.java:430) at org.hibernate.cache.StandardQueryCache.put(StandardQueryCache.java:83) at org.hibernate.loader.Loader.putResultInQueryCache(Loader.java:2194) 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:1695) at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152) at test.uscc.EmpMain.main(EmpMain.java:41)
Name and version of the database you are using: mysql-5.0.41-win32 [
The generated SQL (show_sql=true): Hibernate: SELECT employee.empname, employee.salary, department.dname FROM employee JOIN department on employee.empno = department.empno WHERE sysdate() >= employee.effdate and employee.expdate > sysdate() and employee.salary in (select al.salary from allowances al where al.basicpay= ?)
|