-->
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.  [ 9 posts ] 
Author Message
 Post subject: 2nd level Caching(Ehcache) not working
PostPosted: Thu Apr 19, 2007 6:39 am 
Newbie

Joined: Thu Apr 19, 2007 6:15 am
Posts: 5
Hi All,

I want to use 2nd level caching in my application.
I am giving the code for ehcache.xml file, applicationCcontext-dao.xml and mediatype.hbm.xml file

ehcache.xml file


Code:
<ehcache>   
<defaultCache
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="300"
        timeToLiveSeconds="600"
        overflowToDisk="true"
        diskPersistent="false"
        diskExpiryThreadIntervalSeconds="120"
        memoryStoreEvictionPolicy="LRU"
        />

    <class-cache name="com.gdw.gemini.model.MediaType"
        maxElementsInMemory="300"
        eternal="true"
        overflowToDisk="false"
     />
     
    <cache name="net.sf.hibernate.cache.StandardQueryCache"
        maxElementsInMemory="5"
        eternal="false"
        timeToLiveSeconds="120"
        overflowToDisk="false"
     />

</ehcache>



applicationContext-dao.xml[/u]

Code:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource"><ref bean="dataSource"/></property>
      <property name="mappingDirectoryLocations">
         <list>
            <value>/WEB-INF/hbm</value>
         </list>
        </property>
        <property name="hibernateProperties">
            <props>
               <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
               <prop key="hibernate.cache.use_query_cache">true</prop>
               <prop key="hibernate.cache.use_second_level_cache">true</prop>    
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>                         
            </props>
        </property>
    </bean>


mediaType.hbm.xml file

Code:
<?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>
<!--
    Created by the Middlegen Hibernate plugin 2.2

    http://boss.bekk.no/boss/middlegen/
    http://www.hibernate.org/
-->

<class
    name="com.gdw.gemini.model.MediaType"
    table="media_types"
    lazy="false"
>
    <meta attribute="class-description" inherit="false">
       @hibernate.class
        table="media_types"
    </meta>
    <meta attribute="implement-equals" inherit="false">true</meta>
   <cache usage="read-write"/>
   
    <id
        name="mediaTypeId"
        type="java.lang.Short"
        column="media_type_id"
    >
   
        <meta attribute="field-description">
           @hibernate.id
            generator-class="assigned"
            type="java.lang.Short"
            column="media_type_id"

        </meta>
        <generator class="native" />
    </id>

    <property
        name="mediaTypeName"
        type="java.lang.String"
        column="media_type_name"
        unique="true"
        length="100"
    >
        <meta attribute="field-description">
           @hibernate.property
            column="media_type_name"
            unique="true"
            length="100"
        </meta>   
    </property>
    <property
        name="mediaTypeDesc"
        type="java.lang.String"
        column="media_type_desc"
        length="-1"
    >
        <meta attribute="field-description">
           @hibernate.property
            column="media_type_desc"
            length="-1"
        </meta>   
    </property>
    <property
        name="mediaCapacity"
        type="java.lang.Integer"
        column="media_capacity"
        length="4"
    >
        <meta attribute="field-description">
           @hibernate.property
            column="media_capacity"
            length="4"
        </meta>   
    </property>

    <!-- Associations -->
 
    <!-- bi-directional one-to-many association to Spindle -->

    <set
        name="spindles"
        lazy="true"
        inverse="true"
      cascade="none"

    >
        <meta attribute="field-description">
           @hibernate.set
            lazy="true"
            inverse="true"
            cascade="none"

           @hibernate.collection-key
            column="media_type_id"


           @hibernate.collection-one-to-many
            class="com.gdw.gemini.model.Spindle"
        </meta>
       
      <cache usage="read-only" region="com.gdw.gemini.model.Spindle"></cache>
       
        <key>
            <column name="media_type_id" />
        </key>
       
        <one-to-many
            class="com.gdw.gemini.model.Spindle"
        />
    </set>
    <!-- bi-directional one-to-many association to Project -->

    <set
        name="projects"
        lazy="true"
        inverse="true"
      cascade="none"

    >
        <meta attribute="field-description">
           @hibernate.set
            lazy="true"
            inverse="true"
            cascade="none"

           @hibernate.collection-key
            column="media_type_id"


           @hibernate.collection-one-to-many
            class="com.gdw.gemini.model.Project"
        </meta>
       
        <cache usage="read-only" region="com.gdw.gemini.model.Project"></cache>
       
        <key>
            <column name="media_type_id" />
        </key>
       
        <one-to-many
            class="com.gdw.gemini.model.Project"
        />
    </set>
    <!-- bi-directional one-to-many association to ThresholdLimit -->

    <set
        name="thresholdLimits"
        lazy="true"
        inverse="true"
      cascade="none"

    >
        <meta attribute="field-description">
           @hibernate.set
            lazy="true"
            inverse="true"
            cascade="none"

           @hibernate.collection-key
            column="media_type_id"


           @hibernate.collection-one-to-many
            class="com.gdw.gemini.model.ThresholdLimit"
        </meta>
       
        <cache usage="read-only" region="com.gdw.gemini.model.ThresholdLimit"></cache>
       
        <key>
            <column name="media_type_id" />
        </key>
       
        <one-to-many
            class="com.gdw.gemini.model.ThresholdLimit"
        />
    </set>

</class>
</hibernate-mapping>


I have also added the jar file for ehcache.

It seems that cache is not working. Please try to help to resolve this issue, as I may help many others to solve this, if I came to know.

Thanks in advance.
[/code][/b][/list]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 8:09 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
1) This should probably be in the main forum, since it has nothing to do with Hibernate Tools.

2) This entry:
Code:
    <class-cache name="com.gdw.gemini.model.MediaType"
        maxElementsInMemory="300"
        eternal="true"
        overflowToDisk="false"
     />


is peculiar. I've not seen a class-cache element used before, and it does not seem to be documented. What version of ehcache are you using? Does cacheing occur if you change that to just 'cache'? What log messages are outputted when ehcache spins up? And finally, how are you determining the cache hits and misses?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 10:00 am 
Newbie

Joined: Thu Apr 19, 2007 6:15 am
Posts: 5
Ananasi wrote:
1) This should probably be in the main forum, since it has nothing to do with Hibernate Tools.

2) This entry:
Code:
    <class-cache name="com.gdw.gemini.model.MediaType"
        maxElementsInMemory="300"
        eternal="true"
        overflowToDisk="false"
     />


is peculiar. I've not seen a class-cache element used before, and it does not seem to be documented. What version of ehcache are you using? Does cacheing occur if you change that to just 'cache'? What log messages are outputted when ehcache spins up? And finally, how are you determining the cache hits and misses?


Quote:
Hey Thanks for quick reply. Even if i change to cache, caching doesnt work.

I am determining the cache hits and misses in this way...
I would change the value in database field and save it, refresh it. And then go to my UI and refresh the page. I should see the previous value and not the one which i changed in the database.

As far as log messages are concerned, i am attaching the messages that i received on my console.

I am sorry as this looks weired, but i didnt found any other way to show this.


INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
INFO [SettingsFactory] Scrollable result sets: enabled
INFO [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
INFO [SettingsFactory] Connection release mode: on_close
INFO [SettingsFactory] Default batch fetch size: 1
INFO [SettingsFactory] Generate SQL with comments: disabled
INFO [SettingsFactory] Order SQL updates by primary key: disabled
INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
INFO [SettingsFactory] Query language substitutions: {}
INFO [SettingsFactory] Second-level cache: enabled
INFO [SettingsFactory] Query cache: enabled
INFO [SettingsFactory] Cache provider: org.hibernate.cache.EhCacheProvider
INFO [SettingsFactory] Optimize cache for minimal puts: disabled
INFO [SettingsFactory] Structured second-level cache entries: disabled
INFO [SettingsFactory] Query cache factory: org.hibernate.cache.StandardQueryCacheFactory
INFO [SettingsFactory] Statistics: disabled
INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
INFO [SettingsFactory] Default entity-mode: pojo
INFO [SessionFactoryImpl] building session factory
WARN [Configurator] No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/E:/GDWSoftwares/jboss-4.0.3SP1/server/default/tmp/deploy/tmp42191gdwatlas-exp.war/WEB-INF/lib/ehcache-0.9.jar!/ehcache-failsafe.xml
WARN [EhCacheProvider] Could not find configuration [com.gdw.gemini.model.MediaType]; using defaults.
WARN [CacheFactory] read-only cache configured for mutable class: com.gdw.gemini.model.Project
WARN [EhCacheProvider] Could not find configuration [com.gdw.gemini.model.Project]; using defaults.
WARN [CacheFactory] read-only cache configured for mutable class: com.gdw.gemini.model.Spindle
WARN [EhCacheProvider] Could not find configuration [com.gdw.gemini.model.Spindle]; using defaults.
WARN [CacheFactory] read-only cache configured for mutable class: com.gdw.gemini.model.ThresholdLimit
WARN [EhCacheProvider] Could not find configuration [com.gdw.gemini.model.ThresholdLimit]; using defaults.
INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
INFO [UpdateTimestampsCache] starting update timestamps cache at region: org.hibernate.cache.UpdateTimestampsCache
WARN [EhCacheProvider] Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults.
INFO [StandardQueryCache] starting query cache at region: org.hibernate.cache.StandardQueryCache
WARN [EhCacheProvider] Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.

Please help me to solve this problem.

[/u][/i]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 10:33 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
1) Most recent version of EHCache is 1.2, might want to upgrade. Maybe class-cache is in the older distributions, never seen it before.

2) As evidenced by this line in the logs:
Code:
WARN [Configurator] No configuration found. Configuring ehcache from ehcache-failsafe.xml
your ehcache.xml file is not found by your classloader. Make sure it is in a classloader accessible location.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 10:43 am 
Newbie

Joined: Thu Apr 19, 2007 6:15 am
Posts: 5
Quote:

Thank you once again for your quick reply.

I am sorry to ask you, but i want to get very specific answer so

If you know, can you please tell me where should I put my ehcache.xml file in a classloader accessible location.?

Thanks.



Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 1:55 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Mine is in the default package in the build (e.g. build/classes)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 11:33 pm 
Newbie

Joined: Thu Apr 19, 2007 6:15 am
Posts: 5
Quote:
Even Mine is under build/classes. I dont know then, where am i going wrong.
Actually in my an script i have added this line fr ehcache.

Its like <copy file="ehcache.xml" todir="${build.dir}/WEB-INF/classes" />

Can you throw some more light on this. please....



Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 8:46 pm 
Newbie

Joined: Thu Apr 27, 2006 12:21 am
Posts: 4
it is better to create a CacheManger in the code based on the ehcache configuration file, detail see the ehcache on line documentation


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 5:26 pm 
Beginner
Beginner

Joined: Mon May 21, 2007 5:22 pm
Posts: 27
Location: Salt Lake City
use default-cascade in your hbm.xml file. This will definetly work. !!

_________________
Try 'N' Enjoy !!
Rahul

If helpful do rating ....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.