2017-02-26 1 views
0

J'essaie d'utiliser le cache de second niveau mais j'obtiens une erreur.Impossible de configurer le cache

Voici le hibernate.cfg.xml:

<!DOCTYPE hibernate-configuration PUBLIC 
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 

<hibernate-configuration> 
<session-factory> 
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> 
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property> 
<property name="hibernate.connection.username"></property> 
<property name="hibernate.connection.password"></property> 
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property> 
<property name="show-sql">true</property> 
<property name="format-sql">true</property> 
<property name="hbm2ddl.auto">update</property> 

<!-- second level cache --> 
<property name="cache.use_second_level_cache">true</property> 
<property name="cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property> 
<property name="net.sf.ehcache.configurationResourceName">resource/ehcache.xml</property> 
<!-- query level cache --> 
<property name="cache.use_query_cache">true</property> 
<mapping resource="/resource/student.hbm.xml"/> 
</session-factory> 
</hibernate-configuration> 

Et l'erreur:

Feb 27, 2017 12:39:56 AM org.hibernate.Version logVersion 
INFO: HHH000412: Hibernate Core {5.0.4.Final} 
Feb 27, 2017 12:39:56 AM org.hibernate.cfg.Environment <clinit> 
INFO: HHH000206: hibernate.properties not found 
Feb 27, 2017 12:39:56 AM org.hibernate.cfg.Environment buildBytecodeProvider 
INFO: HHH000021: Bytecode provider name : javassist 
Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.cache.spi.RegionFactory] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189) 
    at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl.<init>(MetadataBuilderImpl.java:663) 
    at org.hibernate.boot.internal.MetadataBuilderImpl.<init>(MetadataBuilderImpl.java:127) 
    at org.hibernate.boot.MetadataSources.getMetadataBuilder(MetadataSources.java:135) 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:655) 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724) 
    at jspider.jogender.hiberTrial.TestClass.main(TestClass.java:19) 
Caused by: org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.EhcacheRegionFactory] 
    at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:84) 
    at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:29) 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234) 
    ... 8 more 
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.cache.EhcacheRegionFactory] as strategy [org.hibernate.cache.spi.RegionFactory] 
    at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:113) 
    at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:71) 
    ... 11 more 

Je ne suis pas sûr de ce manque exactement. Qu'est-ce qui devrait être ajouté pour le faire fonctionner?

Répondre

0

L'erreur est assez spécifique. Vous avez une exception provoquée par une autre, qui est causée par une autre:

Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.cache.EhcacheRegionFactory] as strategy [org.hibernate.cache.spi.RegionFactory] 

Il vous dit qu'il ne peut pas trouver le nom org.hibernate.cache.EhcacheRegionFactory. Cela devrait être org.hibernate.cache.ehcache.EhCacheRegionFactory. Toutefois, cette erreur ne se trouve pas dans le fichier de configuration que vous avez inclus. Peut-être dans resource/ehcache.xml?