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.