简体   繁体   中英

Second level caching in hibernate while migrating from JBoss to TomEE

I need to migrate my application built in GWT from Jboss to tomEE. The application has second level caching enabled in hibernate using Jboss cache. Is it possible to use Jboss cache in tomEE or do I have to find an alternative? If possible, can anyone please help me with the configuration of hibernate.cfg.xml? Below is the configuration

<hibernate-configuration>
<session-factory>
    <property name="hibernate.connection.driver_class">com.sybase.jdbc3.jdc.Sybdriver</property>
    <property name="hibernate.connection.url">xyz...</property>
    <property name="hibernate.connection.username">xyz..</property>
    <property name="hibernate.connection.password">xyz..</property>
    <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
    <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
    <property name="dialect">org.hibernate.dialect.SybaseASE15Dialect</property>
    <property name="generate_statistics">false</property>       
    <property name="jdbc.use_scrollable_resultset">false</property>
    <property name="cache.provider_class">org.hibernate.cache.jbc.JBossCacheRegionFactory</property>
    <property name="cache.use_second_level_cache">true</property>
    <property name="cache.use_minimal_puts">true</property>
    <property name="cache.use_structured_entries">true</property>
    <property name="cache.use_query_cache">true</property>
    <property name="cache.region.factory_class">org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory</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.collection">mvcc-entity</property>
    <property name="cache.region.jbc2.cfg.query">local-query</property>

    <mapping resource="book.hbm.xml" />
</session-factory>
 </hibernate-configuration>

We cannot achieve the second level caching using JBoss cache in TomEE. We have implemented a similar caching mechanism using Ehcache which is a little slow but works fine.

<property name="cache.region.jbc2.cfg.entity">mvcc-entity</property>
<property name="cache.region.jbc2.cfg.collection">mvcc-entity</property>
<property name="cache.region.jbc2.cfg.query">local-query</property>

We see that entity, collection, and query caching are enabled by using JBoss cache implementation specific to JBoss server. In the case of TomEE, we cannot have the same configuration. You would have to implement a different caching technique using different caching technologies available and match it with the usage of second-level cache(like say read-only, read-write, transactional etc.). In a similar setup, I had used "Ehcache" and that had solved the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM