HHH-5210 Query Cache effective only after closing the session that created the cache
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19462 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
8749ae600a
commit
8e76bf9648
|
@ -88,7 +88,7 @@ public class StandardQueryCache implements QueryCache {
|
|||
return false;
|
||||
}
|
||||
else {
|
||||
Long ts = Long.valueOf( session.getTimestamp() );
|
||||
Long ts = new Long( session.getFactory().getSettings().getRegionFactory().nextTimestamp());
|
||||
|
||||
if ( log.isDebugEnabled() ) {
|
||||
log.debug( "caching query results in region: " + cacheRegion.getName() + "; timestamp=" + ts );
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//$Id: QueryCacheTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
|
||||
package org.hibernate.test.querycache;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -41,6 +42,48 @@ public class QueryCacheTest extends FunctionalTestCase {
|
|||
public static Test suite() {
|
||||
return new FunctionalTestClassTestSuite( QueryCacheTest.class );
|
||||
}
|
||||
//https://jira.jboss.org/jira/browse/JBPAPP-4224
|
||||
public void testHitCacheInSameSession() {
|
||||
getSessions().evictQueries();
|
||||
getSessions().getStatistics().clear();
|
||||
Session s = openSession();
|
||||
List list = new ArrayList();
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < 3; i++ ) {
|
||||
Item a = new Item();
|
||||
a.setName( "a" + i );
|
||||
a.setDescription( "a" + i );
|
||||
list.add( a );
|
||||
s.persist( a );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
|
||||
// s.close();
|
||||
// s=openSession();
|
||||
|
||||
s.beginTransaction();
|
||||
String queryString = "from Item";
|
||||
// this query will hit the database and create the cache
|
||||
s.createQuery( queryString ).setCacheable( true ).list();
|
||||
s.getTransaction().commit();
|
||||
|
||||
s.beginTransaction();
|
||||
//and this one SHOULD served by the cache
|
||||
s.createQuery( queryString ).setCacheable( true ).list();
|
||||
s.getTransaction().commit();
|
||||
QueryStatistics qs = s.getSessionFactory().getStatistics().getQueryStatistics( queryString );
|
||||
assertEquals( 1, qs.getCacheHitCount() );
|
||||
assertEquals( 1, qs.getCachePutCount() );
|
||||
s.close();
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
for(Object obj:list){
|
||||
s.delete( obj );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
}
|
||||
|
||||
public void testQueryCacheInvalidation() throws Exception {
|
||||
|
||||
|
|
Loading…
Reference in New Issue