-->
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.  [ 6 posts ] 
Author Message
 Post subject: How to preserve static cache tables after transaction ends?
PostPosted: Thu Apr 27, 2006 10:40 am 
Beginner
Beginner

Joined: Mon Nov 28, 2005 11:03 am
Posts: 39
Location: Madrid
Dear members,

I have the typical country table with information about the countries. It is a static table that doesn't change during our batch process.

I am using transaction for saving amount of big objects every time. What we have detected is that when the transaction ends, the session is closed and the country cache information is lost.

Is there any way to control this situation in order to take a advantage of using transaction for saving smaller portion of data into database but preserving the read-only cache information such as country table?

We are using Hibernate with Spring and Ehcache.

Thanks in advance,

David

_________________
David Leal


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 8:12 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Do you have cache instructions in the Countries class mapping?
http://www.hibernate.org/hib_docs/v3/re ... ance-cache

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 4:39 am 
Beginner
Beginner

Joined: Mon Nov 28, 2005 11:03 am
Posts: 39
Location: Madrid
Thank for your replay kgignatyev,

On country map file we have:

Code:
<hibernate-mapping>
    <class name="com.schinvest.lra.domain.Country" table="lra_country" catalog="lra">
        <!-- This table is used for read only purpose-->
        <cache usage="read-only"/>
        ....
    </class>
</hibernate-mapping>


on the ehcache.xml file we have:

Code:
<ehcache>
  <diskStore path="java.io.tmpdir"/>

  <defaultCache
    maxElementsInMemory="100000"
    eternal="false"
    timeToIdleSeconds="120"
    timeToLiveSeconds="120"
    overflowToDisk="true"
    diskPersistent="false"
    diskExpiryThreadIntervalSeconds="120"
  />
  <cache name="com.schinvest.lra.domain.Country"
     maxElementsInMemory="300"
     eternal="true"
     timeToIdleSeconds="0"
     timeToLiveSeconds="0"
     overflowToDisk="false"
    />
...
</ehcache>


and on the bean sesionFactory definition (Spring) we have:

Code:
<bean id="sessionFactory"   
     
  class=
    "org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource"><ref bean="dataSource"/></property>
  <property name="mappingDirectoryLocations">
    <value>hibernate/mapping</value>
  </property>
  <property name="hibernateProperties">
    <props>
      <prop key="hibernate.max_fetch_depth">3</prop>
      <prop key="hibernate.dialect">
        org.hibernate.dialect.MySQLDialect</prop>
      <prop key="hibernate.cache.use_query_cache">true</prop>
      <prop key="hibernate.cache.use_second_level_cache">true</prop>
      <prop key=
         "hibernate.transaction.flush_before_completion">true</prop>
    </props>
  </property>
</bean>


so the default cache class is ehCache, if we look on the log file we detect that the country table is loaded on cache at the begining of transaction, but when it finished it load again the same table on cache for the next transaction.

We have the transaction on a for-loop, just for process smaller portions of a big backup file, but it is repetitive process, the country table where to look is the same on each iteration, so we would like to keep such information on cache.

We know we could do it BY HAND, putting the country information into a satic map attribute, nevertheless the minimum to ask for cache is precisly such can of saving effort.

On the documentaion you have linked, the cache is correlated with the sesion, so the problem is to avoid clossing the sesion after transaction in order to clear the L1-cache, but not the L2-cache, between transactions.

Thanks in advance,

David

_________________
David Leal


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 10:34 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
If you use queries then you have to enable caching on them

List blogs = sess.createQuery("from Blog blog where blog.blogger = :blogger")
.setEntity("blogger", blogger)
.setMaxResults(15)
.setCacheable(true)
.setCacheRegion("frontpages")
.list();

http://www.hibernate.org/hib_docs/v3/re ... querycache

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 29, 2006 7:28 am 
Beginner
Beginner

Joined: Mon Nov 28, 2005 11:03 am
Posts: 39
Location: Madrid
Dear kgignatyev,

I don't really need to cache the quiery, instead the whole table, ok I am going to try to query al elements and to do what you recomend. I would tell you.

Thanks,

David

_________________
David Leal


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 29, 2006 6:27 am 
Beginner
Beginner

Joined: Mon Nov 28, 2005 11:03 am
Posts: 39
Location: Madrid
I have set the property:

hibernate.cache.use_query_cache = true

but every time the transaction ends on the next transaction the country table is loaded again on cache. That is precisly de effect I want to avoid when transaction ends, because my country table is constant.

Thanks in advance,

David

_________________
David Leal


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.