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