Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting hibernate second level cache
    primarykey
    data
    text
    <p>I am new in hibernate and spring and I experiment with hibernate second level cache. But it seems doesn't work. I have a following test class:</p> <pre><code>@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:applicationContext.xml" }) @TransactionConfiguration @Transactional public class CacheTest extends AbstractTransactionalJUnit4SpringContextTests { @Test public void testCache1() { System.out.println("Running testCache1"); ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); MutableDAO&lt;AppUser&gt; appUserDAO = new MutableDAOImpl&lt;AppUser&gt;(AppUser.class, (SessionFactory) ctx.getBean("OnMediaSessionFactory"), 10); assertNotNull("AppUser DAO is null.", appUserDAO); SessionFactory sessionFactory = (SessionFactory)ctx.getBean("OnMediaSessionFactory"); long numberOfUsers = appUserDAO.countAll(); System.out.println("Number of rows :" + numberOfUsers); final String cacheRegion = AppUser.class.getCanonicalName(); SecondLevelCacheStatistics settingsStatistics = sessionFactory.getStatistics(). getSecondLevelCacheStatistics(cacheRegion); StopWatch stopWatch = new StopWatch(); stopWatch.start(); appUserDAO.findAll(); stopWatch.stop(); System.out.println("Query time : " + stopWatch.getTotalTimeSeconds()); System.out.println(settingsStatistics); } @Test public void testCache2() { System.out.println("Running testCache2"); ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); MutableDAO&lt;AppUser&gt; appUserDAO = new MutableDAOImpl&lt;AppUser&gt;(AppUser.class, (SessionFactory) ctx.getBean("OnMediaSessionFactory"), 10); assertNotNull("AppUser DAO is null.", appUserDAO); SessionFactory sessionFactory = (SessionFactory)ctx.getBean("OnMediaSessionFactory"); long numberOfUsers = appUserDAO.countAll(); System.out.println("Number of rows :" + numberOfUsers); final String cacheRegion = AppUser.class.getCanonicalName(); SecondLevelCacheStatistics settingsStatistics = sessionFactory.getStatistics(). getSecondLevelCacheStatistics(cacheRegion); StopWatch stopWatch = new StopWatch(); stopWatch.start(); appUserDAO.findAll(); stopWatch.stop(); System.out.println("Query time : " + stopWatch.getTotalTimeSeconds()); System.out.println(settingsStatistics); } } </code></pre> <p>and i have</p> <pre><code>&lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt; &lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.use_sql_comments"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.cache.use_query_cache"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.cache.use_second_level_cache"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.generate_statistics"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.cache.use_structured_entries"&gt;true&lt;/prop&gt; </code></pre> <p>but i get output like this:</p> <pre><code>Running testCache1 Number of rows :81 Query time : 0.129 SecondLevelCacheStatistics[hitCount=0,missCount=0,putCount=81,elementCountInMemory=81,elementCountOnDisk=0,sizeInMemory=219634] Running testCache2 Number of rows :81 Query time : 0.063 SecondLevelCacheStatistics[hitCount=0,missCount=0,putCount=81,elementCountInMemory=81,elementCountOnDisk=0,sizeInMemory=219634] </code></pre> <p>what i have to do to get it work ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload