Announcement Announcement Module
Collapse
No announcement yet.
Spring hibernate EHCache dont work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring hibernate EHCache dont work

    Folks,

    I am trying to implement readOnly query cache within spring framework using hibernate and EHCache.

    I have configured show_sql = true.

    Now when First time when I invoke query, I sees hibernate generating query.

    But next time I expect hibernate should return result from cache. But every time I see it generating query repeatively and returning result from database taking same amount of time.

    Any idea please suggest. This is quite urgent.

    This is my hibernate config
    =======================
    <bean id="dareSessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource" ref="dareOracleDataSource"/>
    <property name="mappingResources">
    <list>
    <value>SourceSystem.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <value>
    hibernate.dialect=org.hibernate.dialect.Oracle9Dia lect
    hibernate.show_sql=true
    hibernate.cache.provider_class=org.hibernate.cache .EhCacheProvider
    hibernate.hibernate.cache.use_query_cache=true
    hibernate.cache.use_second_level_cache=true
    </value>
    </property>
    <property name="entityCacheStrategies">
    <value>
    com.dare.beans.SourceSystem=read-only
    </value>
    </property>
    </bean>

    <bean id="cacheDataDAO" class="com.dare.dao.CacheDataDAOSupport" lazy-init="false">
    <property name="sessionFactory" ref="dareSessionFactory"/>
    </bean>
    ================================================

    This is my EHCache Config
    ================================================
    <ehcache><defaultCache
    maxElementsInMemory="10000"
    eternal="false"
    timeToIdleSeconds="120"
    timeToLiveSeconds="120"
    overflowToDisk="true"
    diskPersistent="false"
    diskExpiryThreadIntervalSeconds="120"
    />
    <cache name="com.dare.beans.SourceSystem"
    maxElementsInMemory="20"
    eternal="false"
    overflowToDisk="false"
    timeToIdleSeconds="300"
    timeToLiveSeconds="600"
    /></ehcache>
    =================================================

    Now this is my Object-DB mapping file SourceSystem.hbm.xml
    ================================
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

    <hibernate-mapping package="com.dare.beans" default-lazy="false">

    <class name="SourceSystem" table="SOURCE_SYSTEM"
    dynamic-update="false">
    <meta attribute="class-description">
    Source System business object. @author Shivnarayan
    </meta>
    <cache usage="read-only" />
    <id name="sourceSystemId" type="string" unsaved-value="null">
    <column name="SOURCE_SYSTEM_ID" sql-type="char(32)"
    not-null="true" />
    <generator class="native" />
    </id>

    <property column="SYSTEM_ACRONYM" name="systemAcronym" />
    <property column="EXCEPTION_PROCESSING_METHOD"
    name="exceptionMethod" />
    <property column="BUSINESS_AREA" name="businessArea" />
    </class>

    </hibernate-mapping>
    ============================================

    My DAO Class :
    public class CacheDataDAOSupport implements CacheDataDAO {

    private HibernateTemplate hibernateTemplate;

    public void setSessionFactory(SessionFactory sessionFactory) {
    this.hibernateTemplate = new HibernateTemplate(sessionFactory);
    this.hibernateTemplate.setCacheQueries(true);
    }


    public List<SourceSystem> getSendingSystemIdentifier() throws DataAccessException {
    return this.hibernateTemplate.loadAll(SourceSystem.class) ;
    }

    }
    ==========================================

    Please help.

  • #2
    I have just changed hibernate config with following properties, but problem remains same
    <value>
    hibernate.dialect=org.hibernate.dialect.Oracle9Dia lect
    hibernate.show_sql=true
    hibernate.cache.provider_class=org.hibernate.cache .EhCacheProvider
    hibernate.cache.use_query_cache=true
    hibernate.cache.use_second_level_cache=true
    hibernate.cache.provider_configuration_file_resour ce_path=file:H:/GSS_DARE/gss/GSS_DARE/config/ehcache.xml
    </value>

    Comment


    • #3
      It really helps to wrap code in [code] [ /code] tags! Is it possible to see the SQL that is being executed?
      Last edited by karldmoore; Aug 29th, 2007, 10:48 AM.

      Comment


      • #4
        Please put ecache in "debug" mode in your log4j configuration.

        This will tell wether your Hibernate objects are stored and/or found in the cache, so that you can pinpoint the problem.

        Comment


        • #5
          Its working

          Thank you all very much for your responses. Actually its working..Everytime it fetches result from cache not from database.
          Last edited by shivnarayan; Jul 5th, 2007, 12:04 AM. Reason: test

          Comment


          • #6
            So what was the fix? Or was it always working?
            Last edited by karldmoore; Aug 29th, 2007, 10:48 AM.

            Comment


            • #7
              It was working previously. actually I haven't analyzed log before posting this message. Sorry for that.

              Comment


              • #8
                Originally posted by shivnarayan View Post
                It was working previously. actually I haven't analyzed log before posting this message. Sorry for that.
                Ahhhh ok, not a problem it's just nice to know what was going on .
                Last edited by karldmoore; Aug 29th, 2007, 10:48 AM.

                Comment

                Working...
                X