-->
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.  [ 2 posts ] 
Author Message
 Post subject: Distributed query cache
PostPosted: Thu Feb 08, 2007 12:15 pm 
Newbie

Joined: Mon Jan 08, 2007 10:28 am
Posts: 11
Hibernate version: 3.2.2

Hibernate configuration: (with Spring support)
Code:
<bean id ="myDataSource"
   class="org.springframework.jndi.JndiObjectFactoryBean">
   <property name="jndiName">
      <value>java:comp/env/jdbc/MyDataSource</value>
   </property>
</bean>
   
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
   <property name="dataSource" ref="myDataSource"/>
   <property name="mappingResources">
      <list>
         <value>clara/prototype/persistant/hibernatoo/mapping/oracle/Marche.hbm.xml</value>
      </list>
   </property>
   <property name="hibernateProperties">
      <props>
         <prop key="hibernate.cache.provider_class">org.hibernate.cache.OptimisticTreeCacheProvider</prop>
         <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JOTMTransactionManagerLookup</prop>
         <!-- prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop -->
         <prop key="hibernate.cache.use_query_cache">true</prop>
         <prop key="hibernate.show_sql">false</prop>
         <prop key="hibernate.generate_statistics">false</prop>
         <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
      </props>
   </property>
</bean>


Mapping documents: Marche.hbm.xml :
Code:
<hibernate-mapping package="clara.prototype.persistant.hibernatoo">
    <class name="Marche" table="MARCHE">
       <!-- Configuration de cache de second niveau avec EHCache
       <cache usage="read-write"/>
       -->
       <!-- Configuration de cache de second niveau avec JBoss-Cache -->
       <cache usage="transactional"/>
        <id name="id" type="integer">
            <column name="IDMAR" precision="4" scale="0" />
            <generator class="sequence">
                <param name="sequence">SEQ_MARCHE</param>
            </generator>
        </id>
        <version name="version" type="int">
            <column name="VERSION" precision="22" scale="0" not-null="true" />
        </version>
        <property name="nom" type="string">
            <column name="NOM" length="30" unique="true" />
        </property>
        <property name="description" type="string">
            <column name="DESCRIPTION" length="50" />
        </property>
    </class>
</hibernate-mapping>


JBoss-Cache configuration:
NodeLockingScheme=OPTIMISTIC
CacheMode=REPL_ASYNC
Cluster=Yes

Code between sessionFactory.openSession() and session.close(): (with Spring HibernateTemplate)
Code:
public class GenericDaoHibernateImpl extends HibernateDaoSupport {
    public List getAll(Class type) throws DataAccessException {

        List persistantObjects = null;
        getHibernateTemplate().setCacheQueries(true);
        persistantObjects = getHibernateTemplate().loadAll(type);
        return persistantObjects;
       
    }
}


Name and version of the database you are using: Oracle 10g

The generated SQL (show_sql=true):
Code:
select this_.IDMAR as IDMAR3_0_, this_.VERSION as VERSION3_0_, this_.
NOM as NOM3_0_, this_.DESCRIPTION as DESCRIPT4_3_0_ from MARCHE this_|select this_.IDMAR as IDMAR3_0_, this_.VERSION as VERSION3_0_, this_.NOM as NOM3_0_, this_.DESCRIPTION as DESCRIPT4_3_0_ from MARCHE this_


My problem:
We have to deploy the application, with this second level cache configuration, on 2 application servers. The nodes (entities, queries) are added to the cache and replicated on the other cache (distributed). The query results are used by the instance of the application that insert it into the cache before. But the replicated nodes corresponding to these query result are never used by the other instance of the application.
Exactly the same problem appears if we replace JBoss-Cache by EHCache.

My question:
Is Hibernate supposed to use query result in cache even if it comes from an other instance of the application ?
Does Hibernate work only with invalidation mode ?

More information:
Here is the cache (same on every cache of the cluster) when I call the method "getAll(Marche.class)" :
Code:
  /clara

    /prototype

      /persistant

        /hibernatoo

          /Marche

            /clara.prototype.persistant.hibernatoo.Marche#1
item: CacheEntry(clara.prototype.persistant.hibernatoo.Marche)[35,marche,descMarche1]

            /clara.prototype.persistant.hibernatoo.Marche#2
item: CacheEntry(clara.prototype.persistant.hibernatoo.Marche)[9,marche2,descMarche2]

            /clara.prototype.persistant.hibernatoo.Marche#3
item: CacheEntry(clara.prototype.persistant.hibernatoo.Marche)[1,marche3,descMarche3]

            /clara.prototype.persistant.hibernatoo.Marche#8
item: CacheEntry(clara.prototype.persistant.hibernatoo.Marche)[0,marche5,null]

            /clara.prototype.persistant.hibernatoo.Marche#16
item: CacheEntry(clara.prototype.persistant.hibernatoo.Marche)[3,marche4,null]

  /org

    /hibernate

      /cache

        /StandardQueryCache

          /sql: select this_.IDMAR as IDMAR3_0_, this_.VERSION as VERSION3_0_, this_.NOM as NOM3_0_, this_.DESCRIPTION as DESCRIPT4_3_0_ from MARCHE this_; parameters: ; transformer: org.hibernate.transform.RootEntityResultTransformer@221293
item: [11709474752, 16, 8, 1, 2, 3]


If I call "getAll(Marche.class)" again on the same instance of the application, I can see the cache is used and not the database. Everything is OK.

But If I call the same method "getAll(Marche.class)" on the other instance of the application, the cache is not used... The query is executed on the database and an other node (in org/hibernate/cache/StandardQueryCache) is inserted in the cache :
Code:
          /sql: select this_.IDMAR as IDMAR3_0_, this_.VERSION as VERSION3_0_, this_.NOM as NOM3_0_, this_.DESCRIPTION as DESCRIPT4_3_0_ from MARCHE this_; parameters: ; transformer: org.hibernate.transform.RootEntityResultTransformer@2973c3
item: [11709474752, 16, 8, 1, 2, 3]


We can see that the instance of the ResultTransformer is different in the query result nodes... :
- org.hibernate.transform.RootEntityResultTransformer@221293
- org.hibernate.transform.RootEntityResultTransformer@2973c3

But we don't know exactly what's the problem.

Can somebody help us ?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 1:58 pm 
Newbie

Joined: Mon Jun 18, 2007 9:17 am
Posts: 4
Hi rkrol,

I have exactly the same problem but with Tangosol Coherence cache product.

Did you solve this problem already or may be anybody knows the solution?

Regards


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