-->
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.  [ 3 posts ] 
Author Message
 Post subject: Disable cache for the part of a application
PostPosted: Thu Oct 30, 2008 8:32 am 
Newbie

Joined: Wed Jun 18, 2008 5:46 am
Posts: 7
Hibernate version: 3.2.6.ga

Name and version of the database you are using: postgreSQL, 8.3-603.jdbc3

Hello everyone,

I've got a problem with query cache and import function in my project. I'm using query cache in my application:

app. context:

Code:
<bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
       <property name="configLocation" value="classpath:hibernate.cfg.xml" />
       <property name="hibernateProperties">
           <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.query.substitutions">true 'T', false 'F'</prop>
                <prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
                <prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
                <prop key="hibernate.show_sql">${hibernate.show.sql}</prop>
                <prop key="hibernate.use_sql_comments">${hibernate.show.sql}</prop>
                <prop key="hibernate.jdbc.use_scrollable_resultset">true</prop>
                <prop key="hibernate.jdbc.batch_size">20</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.hibernate.generate_statistics">true</prop>
               
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
             <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
             <prop key="hibernate.cache.use_structured_entries">true</prop>
             <prop key="hibernate.cache.use_query_cache">true</prop>
            
             <prop key="hibernate.c3p0.min_size">5</prop>
            <prop key="hibernate.c3p0.max_size">20</prop>
            <prop key="hibernate.c3p0.timeout">1800</prop>
            <prop key="hibernate.c3p0.max_statements">50</prop>

           </props>
       </property>
      <!--<property name="dataSource" ref="dataSource"/>-->
       <property name="dataSource" ref="${hibernate.dataSource.name}"/>
   </bean>
   
   
    <bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="${hibernate.connection.driver_class}" />
        <property name="jdbcUrl" value="${hibernate.connection.url}" />
        <property name="properties">
            <props>
            <prop key="user">${hibernate.connection.username}</prop>
                <prop key="password">${hibernate.connection.password}</prop>
            </props>
        </property>
    </bean>

and I need disable query cache for part of my project where I'm importing data. Reason is simple, it's a lot of iterations and using cache cause java
heap space error. In my import function I'm using batching feature like this:

Code:
//define session and transaction
Session session = getSessionFactory().openSession();
Transaction transaction = session.beginTransaction(); 
Integer count = 1;


Inside import function loop (over 100 000 iterations):

Code:
//some SQL query
hql = new StringBuffer();
hql.append("SELECT ...");
query = session.createQuery(hql.toString());
result = query.uniqueResult();
count++

count++;
if (count % 20 == 0) {
   session.flush();
   session.clear();



This import cause java heap space error. When I turn off query cache :

Code:
<prop key="hibernate.cache.use_query_cache">false</prop>


import works fine. But I need this cache enabled for rest of my application, so I tried turn of cacheable option in query:

Code:
hql = new StringBuffer();
hql.append("SELECT ...");
query = session.createQuery(hql.toString());
query.setCacheable(false);


Nothing changed. Head space error again. This is part of my log file (cacheable option in the query is true and query cache in XML file is enabled):

Code:
INFO  2008-10-29 16:48:53 MatrixOfferDaoImpl:importData(line 138) - Importuje se nabidka cislo: 5172
DEBUG 2008-10-29 16:48:53 UpdateTimestampsCache:preinvalidate(line 50) - Pre-invalidating space [public.ges_hotel]
DEBUG 2008-10-29 16:48:53 UpdateTimestampsCache:preinvalidate(line 50) - Pre-invalidating space [public.ges_price]


as we can see import still interact with cache. Than I tried this:

Code:
session.setCacheMode(CacheMode.IGNORE);


but nothing changed.

So question is: Is there any way to disable cache for part of my application? For example in the session or query object?

Thanks for all answers.

Regards,
Martin Valach


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2008 6:31 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
on that cleaning code fragment, evict also the queries

Code:
session.evictQueries();



and evict individual entities involved on the queries

Code:
session.evict(A.class);

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2008 5:29 am 
Newbie

Joined: Wed Jun 18, 2008 5:46 am
Posts: 7
gonzao_diaz wrote:
on that cleaning code fragment, evict also the queries

Code:
session.evictQueries();



and evict individual entities involved on the queries

Code:
session.evict(A.class);


Thanks for answer but this also didn't work. I call evict on every obtained object + call evictQueries() in the cleaning code but still heap space error and still :

Code:
INFO  2008-10-31 10:24:01 MatrixOfferDaoImpl:importData(line 141) - Importuje se nabidka cislo: 54162
DEBUG 2008-10-31 10:24:01 UpdateTimestampsCache:preinvalidate(line 50) - Pre-invalidating space [public.ges_hotel]
DEBUG 2008-10-31 10:24:01 UpdateTimestampsCache:preinvalidate(line 50) - Pre-invalidating space [public.ges_price]


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