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