-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: How to tell if my second level cache is working
PostPosted: Fri Sep 16, 2011 4:56 am 
Newbie

Joined: Sun Mar 27, 2005 1:22 pm
Posts: 15
Hi,

I have a spring JPA hibernate app and I am trying to switch on second level caching but I am unsure if it is actually working as I can still see the SQL on the console (I am pretty sure that means it is not working). ANy help would be greatly appreciated. Thanks.

Here is my config & code...

Object...

Code:
@Entity()
@Table(name = "wiki_file")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class WikiFile {
...


persistance.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="medical">
      <properties>
      <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider"/>
      <property name="hibernate.cache.use_second_level_cache" value="true"/>
      </properties>
   </persistence-unit>
</persistence>



application context...

Code:
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">     
        <property name="dataSource" ref="dataSource" />
           
        <property name="jpaVendorAdapter">
            <bean
                class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="database" value="MYSQL" />
                <property name="showSql" value="true" />
                <property name="generateDdl" value="true"></property>
            </bean>
        </property>
    </bean>

    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost/medical" />
        <property name="username" value="yee" />
        <property name="password" value="haa" />               
     </bean>


When I ask for the object repeatedly it shows the select being run again

Code:
Hibernate: select wikifile0_.wiki_file_id as wiki1_3_, wikifile0_.ADMIN_only as ADMIN2_3_, wikifile0_.content as content3_, wikifile0_.delete_date as delete4_3_, wikifile0_.file_name as file5_3_, wikifile0_.file_size as file6_3_, wikifile0_.mime_type as mime7_3_, wikifile0_.read_only as read8_3_, wikifile0_.virtual_wiki as virtual9_3_ from wiki_file wikifile0_ where wikifile0_.wiki_file_id=2 limit ?
Hibernate: select wikifile0_.wiki_file_id as wiki1_3_, wikifile0_.ADMIN_only as ADMIN2_3_, wikifile0_.content as content3_, wikifile0_.delete_date as delete4_3_, wikifile0_.file_name as file5_3_, wikifile0_.file_size as file6_3_, wikifile0_.mime_type as mime7_3_, wikifile0_.read_only as read8_3_, wikifile0_.virtual_wiki as virtual9_3_ from wiki_file wikifile0_ where wikifile0_.wiki_file_id=2 limit ?
Hibernate: select wikifile0_.wiki_file_id as wiki1_3_, wikifile0_.ADMIN_only as ADMIN2_3_, wikifile0_.content as content3_, wikifile0_.delete_date as delete4_3_, wikifile0_.file_name as file5_3_, wikifile0_.file_size as file6_3_, wikifile0_.mime_type as mime7_3_, wikifile0_.read_only as read8_3_, wikifile0_.virtual_wiki as virtual9_3_ from wiki_file wikifile0_ where wikifile0_.wiki_file_id=2 limit ?


If I leave out the hibernate.cache.use_second_level_cache in the persitance.xml file hibernate complains about the object so I know that hibernate knows the object is to be cached I just cannot see any evidence that it is (or not).

Thanks.

hibernate 3.2 spring 3.0.5


Top
 Profile  
 
 Post subject: Re: How to tell if my second level cache is working
PostPosted: Mon Sep 26, 2011 8:09 am 
Newbie

Joined: Sun Mar 27, 2005 1:22 pm
Posts: 15
Shameless bump.


Top
 Profile  
 
 Post subject: Re: How to tell if my second level cache is working
PostPosted: Mon Sep 26, 2011 9:10 am 
Newbie

Joined: Wed Oct 31, 2007 6:04 am
Posts: 8
Location: Cologne, Germany
Try setting the log level for org.hibernate.cache.EhCache to DEBUG, then you should see what EhCache is up to.


Top
 Profile  
 
 Post subject: Re: How to tell if my second level cache is working
PostPosted: Mon Sep 26, 2011 2:32 pm 
Newbie

Joined: Sun Mar 27, 2005 1:22 pm
Posts: 15
I set

log4j.logger.org.hibernate.cache=DEBUG

and the only line it ever outputs (at start up) is

19:25:13,226 INFO RegionFactoryCacheProviderBridge:61 - Cache provider: net.sf.ehcache.hibernate.EhCacheProvider

It seems to accept that there is to be a cache with cached objects but never actually places any objects in the cache. All very strange.

I dont know if my entity manager injection would be non standard for caching, just cannot think of anything else.

Code:
@Transactional
public class WikiFileManager {

   private EntityManager em ;
   
   /**
    *
    * @param em
    */
    @PersistenceContext
    public void setEntityManager(EntityManager em) {
        this.em = em;
    }

   /**
    *
    * @param id
    * @return
    */
   public WikiFile get(int id) {
      return (WikiFile)em.find(WikiFile.class, id);
   }
   


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.