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: JPA + Jboss Second Level Cache
PostPosted: Wed Jan 20, 2010 2:45 am 
Newbie

Joined: Mon Jan 11, 2010 9:46 am
Posts: 2
i'm facing a problem while i's trying to configure JPA second level cache with JBoss cache

i'm using hibernate 3.2.5.ga and Jboss cache 1.4.1
persistence.xml
Code:
<persistence-unit name="JPAJbossCachePU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>model.Item</class>
    <shared-cache-mode>ALL</shared-cache-mode>
    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
      <property name="hibernate.connection.username" value="root"/>
      <property name="hibernate.connection.password" value="admin"/>
      <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/ehabt"/>
      <property name="hibernate.show_sql" value="true"/>
      <property name="hibernate.generate_statistics" value="true"/>
      <property name="hibernate.cache.use_second_level_cache" value="true"/>
      <property name="hibernate.cache.use_query_cache" value="true"/>


      <property name="cache.provider_class" value="org.hibernate.cache.OptimisticTreeCacheProvider"/>
      <property name="transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTSTransactionManagerLookup"/>
      <property name="net.sf.ehcache.configurationResourceName" value="jboss-cache.xml"/>

    </properties>
  </persistence-unit>


the error
Code:
[color=#FF0000]Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: JPAJbossCachePU] Unable to build EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
        at client.Main.main(Main.java:25)
Caused by: org.hibernate.HibernateException: Could not instantiate cache implementation
        at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:64)
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:214)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
        ... 4 more
Caused by: org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]
        at org.hibernate.cache.NoCacheProvider.buildCache(NoCacheProvider.java:21)
        at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:61)
        ... 8 more
Java Result: 1[/color]


but if i replaced the Jboss cache with ehcache every thing works fine
Code:
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
      <property name="net.sf.ehcache.configurationResourceName" value="ehcache.xml"/>

      <!--
      <property name="cache.provider_class" value="org.hibernate.cache.OptimisticTreeCacheProvider"/>
      <property name="transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTSTransactionManagerLookup"/>
      <property name="net.sf.ehcache.configurationResourceName" value="jboss-cache.xml"/>


and these configuration works fine with me in a simple hibernate application so why it doesn't work in JPA?

thank's in advance


Top
 Profile  
 
 Post subject: Re: JPA + Jboss Second Level Cache
PostPosted: Wed Jan 20, 2010 4:27 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
1. Why not try to use the latest official releases, such as Hiberante 3.3.2 GA and JBossCache 3.2.1.GA ?

2. Beside the problem you mention, there's another thing to consider:
In your example you are using transaction-type="RESOURCE_LOCAL", but with JBossCache you need "JTA"
JBoss Cache used as 2Lcache implementation for Hiberante requires integration with a JTA in order to meet the requirements of the second level caching use case. Please see
http://www.jboss.org/file-access/default/members/jbossclustering/freezone/docs/hibernate-caching/3.3/en-US/html/introduction-requirements.html
section 1.2.2

Why is JTA required in this environment?
Without JTA integration it easily will happen that 2LC remains in an inconsistent state:
Here's a concrete example:

1. load an existent instance from db and modify it
2. flush
3. rollback

After flushing, without JTA-integration the 2L cache returns the cached instance in it's modified state, although it was never commited! This even in further transactions and other sessions, until the instance is evicted from 2L cache!


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.