Hibernate criteria query is returning me stale results.
I have a simple table ApplicationLog in Hsqldb 1.8.0
A seperate client inserts data into this table.
I am querying this table from another java client. I find that the criteria query count is not correct if this querying java client is left running.(i.e if the inserts happen via the other client , when I query I dont see those results - the other client does commit and I can view the inserted statements from a sql client - only my hsql client has problems viewing the new data)
If I close the client and restart it the data returned.
Here is my code for querying:
SessionFactory sessionFactory = HibernateConfigurer.getFactory(); Session session = sessionFactory.openSession(); Criteria criteria = session.createCriteria( ApplicationLog.class).setCacheMode(CacheMode.IGNORE);
if(keys != null) { int size = keys.length; Long[] allKeys = new Long[size]; for (int i = 0; i < size; ++i) { allKeys[i] = new Long(keys[i]); } criteria.add( Restrictions.in( "applicationLogItemKey", allKeys)); } if((from != null) && (to != null)) { criteria.add(Restrictions.ge( "logTime", from)); criteria.add(Restrictions.le( "logTime", to)); } else { if(from != null) { criteria.add(Restrictions.ge( "logTime", from)); } else if(to != null) { criteria.add(Restrictions.le( "logTime", to)); } } criteria.setFirstResult(startNumber); criteria.setMaxResults(pageSize); criteria.addOrder(Order.desc("logTime")); List applicationLogs = criteria.list(); session.close(); return applicationLogs;
I tried different cache modes thinking I am only hitting the cache. I also tried evicting the class in question. But nothing helps. I see only stale data and not the newly inserted data unless I restart my client.
Can someone help please.
|