Question

Voici ma configuration: Hibernate 3.3.1.GA, JBoss 5.1.0.GA, JBoss Cache 3.2.0.GA.

Je fais la configuration d'Hibernate comme décrit ici: http://www.jboss.org/community/wiki/ClusteredJPAHibernateSecondLevelCachingAchat >

<hibernate-configuration>

    <session-factory>

         <property name="cache.use_second_level_cache">true</property>
         <property name="cache.use_query_cache">true</property>
         <property name="cache.region.factory_class">org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactoryctory</property>
         <property name="cache.region.jbc2.cachefactory>java:CacheManager</property>
         <property name="cache.region.jbc2.cfg.entity">mvcc-entity</property>
         <property name="cache.region.jbc2.cfg.query">local-query</property>
         <property name="cache.region_prefix">tempdb</property>

         ... other non-caching related configuration

    </session-factory>

</hibernate-configuration>

mais l'erreur concernant l'obtention de la propriété spécifiée n'est pas valide:

Caused by: java.lang.IllegalArgumentException: No such property cache for bean org.jboss.hibernate.jmx.Hibernate available [statisticsServiceName, beanName, defaultSchema, defaultCatalog, sessionFactoryName, querySubstitutions, secondLevelCacheEnabled, password, version, statGenerationEnabled, maxFetchDepth, username, useStructuredCacheEntriesEnabled, datasourceName, dirty, streamsForBinaryEnabled, getGeneratedKeysEnabled, hbm2ddlAuto, minimalPutsEnabled, instance, jdbcBatchSize, jdbcScrollableResultSetEnabled, cacheRegionFactoryClass, dialect, scanForMappingsEnabled, runningSince, cacheRegionPrefix, class, cacheProviderClass, sessionFactoryRunning, batchVersionedDataEnabled, harUrl, queryCacheEnabled, sessionFactoryInterceptor, deployedCacheManagerJndiName, showSqlEnabled, reflectionOptimizationEnabled, jdbcFetchSize, listenerInjector, sqlCommentsEnabled, deployedCacheJndiName, controller]

Je ne peux donc pas utiliser " cache.region.factory_class " propriété mais seulement " cacheRegionFactoryClass " (qui est indiqué dans une exception).

Je ne peux utiliser aucune autre propriété comme cache.region. * et je ne peux donc pas configurer le cache de second niveau pour mon veille prolongée.

Quelqu'un peut-il me donner un lien sur la manière de configurer JBoss Cache 3.2 avec JBoss 5.1? Je suis particulièrement intéressé par JndiSharedJBossCacheRegionFactory et JndiMultiplexedJBossCacheRegionFactory.

Était-ce utile?

La solution

Répondant à ma propre question.

Il s’est avéré que vous ne pouvez pas utiliser JBoss Cache avec Hibernate dans JBoss 5.1 si vous démarrez Hibernate en tant que mbean, c’est-à-dire mettez le fichier de configuration Hibernate dans le dossier de déploiement du serveur JBoss.

Cela se produit car mbean n'accepte pas de paramètres tels que "hibernate.cache. *". (et c’est exactement ce qu’est une exception).

Ma solution consiste donc à initialiser Hibernate à partir de code Java et à utiliser hibernate.xml.

Configuration configuration = new Configuration();
Properties properties = configuration.getProperties();

properties.put("hibernate.connection.datasource", "java:/MSSQLDMDS");
properties.put("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect");
properties.put("hibernate.transaction.factory_class", "org.hibernate.transaction.JTATransactionFactory");
properties.put("hibernate.current_session_context_class", "org.hibernate.context.JTASessionContext");
properties.put("hibernate.transaction.manager_lookup_class", "org.hibernate.transaction.JBossTransactionManagerLookup");

properties.put("hibernate.cache.use_second_level_cache", "true");
properties.put("hibernate.cache.use_query_cache", "false");
properties.put("hibernate.cache.region.factory_class", "org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory");
properties.put("hibernate.cache.region.jbc2.cachefactory", "java:CacheManager");
properties.put("hibernate.cache.region.jbc2.cfg.entity", "mvcc-entity");

File mappings = getHibernateMappingDir();
configuration.addDirectory(mappings);

sessionFactory = configuration.buildSessionFactory();

Autres conseils

@Yury Litvinov, ces propriétés sont de nouvelles propriétés qui n'ont pas été mappées vers des attributs d'hibernation de MBean car le MBean d'Hibernate n'est plus géré. Je ne recommanderais pas que vous déployiez Hibernate en tant que MBean.

Après quelques recherches, j'ai réussi à démarrer Hibernate + JBossCache avec cette configuration.

<hibernate-configuration xmlns="urn:jboss:hibernate-deployer:1.0">
   <session-factory name="java:/hibernate/SessionFactory" bean="jboss.har:service=Hibernate">
      <property name="datasourceName">java:/MSSQLDMDS</property>
      <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>      
      <property name="hbm2ddlAuto">create</property>

      <property name="secondLevelCacheEnabled">true</property>
      <property name="queryCacheEnabled">false</property>

      <property name="cacheProviderClass">org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory</property>
      <property name="deployedCacheManagerJndiName">java:CacheManager</property>      

      <depends>jboss.cache:service=CacheManager</depends>
      <depends>jboss:service=Naming</depends>
      <depends>jboss:service=TransactionManager</depends>
   </session-factory>
</hibernate-configuration>

Cependant, je ne peux toujours pas spécifier (obtenir la même erreur) les paramètres suivants: "hibernate.cache.region.jbc2.cfg.entity", "hibernate.cache.region.jbc2.cfg.collection", "hibernate.cache.region.jbc2.cfg.query".

Sans spécifier ces paramètres, je ne peux pas contrôler quelle instance de cache sera utilisée pour la mise en cache des entrées, des collections et des requêtes.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top