Results 1 to 4 of 4

Thread: Spring - Hibernate - EHCache - Web App

  1. #1
    Join Date
    Jun 2005
    Posts
    4

    Default Spring - Hibernate - EHCache - Web App

    Hello All,

    I am trying to enable EHCahce for my spring-hibernate app running in a web applicaiton. I am using Spring 1.1.3 and Hibernate 2.1.

    It appears that the cache is not intercepting and caching my database calls as there seems to be no reduction in the SQL displayed to the console.

    What are the steps to enable the cache with spring?

    Here is what I have done so far....

    added the below to my hibernate context file inside the sessionFactory configuration.

    Code:
    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
            <property name="dataSource"><ref bean="topupDataSource"/></property>
            <property name="mappingResources">
                <list>
                    <value>com/macalla/topup/model/Order.hbm.xml</value>
                    ... left out for space reasons
                    <value>com/macalla/topup/model/VCustomerSearch.hbm.xml</value>
                </list>
            </property>
            <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.use_outer_join">false</prop>
                <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.Provider</prop>
                <prop key="hibernate.hibernate.cache.use_query_cache">true</prop>
            </props>
            </property>
        </bean>
    Created an EHCache.xml file ...

    Code:
    <ehcache>
    
        <diskStore path="java.io.tmpdir"/>
    
        <!-- ehcache requires a default cache -->
        <defaultCache
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="true"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            />
    
        <!-- The SystemValue Cache&#58; cached for 2 hrs &#40;7200 secs&#41; -->
        <cache name="com.macalla.topup.model.SystemValue"
            maxElementsInMemory="100"
            eternal="false"
            timeToIdleSeconds="7200"
            timeToLiveSeconds="7200"
            overflowToDisk="false"
            />
    
        <!-- The TransPaymentState Cache&#58; cached for infinity -->
        <cache name="com.macalla.topup.model.TransPaymentState"
            maxElementsInMemory="100"
            eternal="false"
            timeToIdleSeconds="0"
            timeToLiveSeconds="0"
            overflowToDisk="false"
            />
    
    
        <!-- Standard Qurey Cache -->
        <cache name="net.sf.hibernate.cache.StandardQueryCache"
            maxElementsInMemory="5"
            eternal="false"
            timeToLiveSeconds="120"
            overflowToDisk="false"/>
    
    ETC ETC ETC 
    
    </ehcache>
    I have also added the cache element to the mapping files. I am aware jcs is deprecated, but im using XDoclaet tags to generate stuff so this is a segment from my mapping file. I am sure that ehcache still supports this tag anyhow.

    Code:
    <jcs-cache usage="read-write" />
    Any other steps I need to do?? Do I need to create an spring managed instance of the cache manager and inject it to some component?

    I am aware of the change in the providor class for EHCache in hibernate as of version 2.1.8, but I think my version of Hibernate is pre-2.1.8, and at any rate I get an instantiation error if I try to use the new class.

    Any help appreciated. Thanks

    Colm

  2. #2
    Join Date
    Jun 2005
    Posts
    4

    Default

    I wrote a Junit and it appears the cache is working, although not as well as I would have like, the posted configuration seems to be all that is needed, so this thread can be closed.

  3. #3

    Default

    Could you please show me an example of the cache configuration generation using xdoclet?
    Neeraj Kumar

  4. #4
    Join Date
    Jun 2005
    Posts
    4

    Default

    This seems to work fine...

    Code:
    /**
     *        
     *
     *        @hibernate.class
     *         table="MCS_USERS_PRODUCTS"
     *      @hibernate.jcs-cache usage="read-write"
     *
    */
    and for method level cahce...

    Code:
    /** 
         *            @hibernate.set
         *             lazy="true"
         *             inverse="true"
         *             cascade="none"
         *            @hibernate.collection-key
         *             column="SERVICEID"
         *            @hibernate.collection-one-to-many
         *             class="com.macalla.topup.model.Product"
         *            @hibernate.jcs-cache usage="read-write"
         *         
         */
    Thats it, simply run x-doclet and it should add a <jcs-cache> element to your hbm files. <jcs-cache> is deprecated, but still works with ehcache. x-doclet does not support the new cache tag.

Similar Threads

  1. Replies: 7
    Last Post: Sep 15th, 2010, 07:25 AM
  2. Replies: 5
    Last Post: Feb 3rd, 2009, 05:19 AM
  3. EHCache + Hibernate + Spring
    By BenPoweski in forum Data
    Replies: 1
    Last Post: Oct 5th, 2005, 05:18 AM
  4. Replies: 2
    Last Post: Jul 31st, 2005, 11:05 PM
  5. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •