2012-08-06 13 views
5

Przeczytałem inne wątki na ten temat na ten temat, ale żadne z rozwiązań nie działa dla mnie.Jak skonfigurować pamięć podręczną drugiego poziomu w Hibernate 4.1.5 SP1?

Próbowałem oddanie w moim hibernate.cfg.xml:

<property name="hibernate.cache.region.factory_class">org.hibernate.cache.spi.EntityRegion</property> 

zawsze uzyskać ten błąd: nie mógł instancję RegionFactory [org.hibernate.cache.spi.EntityRegion]

Próbowałem także większość sugestii z wątków na stronach Hibernuj, ale bez powodzenia.

Jak mogę to skonfigurować?

Odpowiedz

11

Cóż, znalazłem odpowiedź (od użytkownika YouTube):

To get it working:

1) I use hibernate-release-4.1.0.Final or later versions. So I've added jars from its lib\optional\ehcache directory

2) My hibernate.cfg.xml contains:

<property name="cache.region.factory_cla­ss">org.hibernate.cache.ehcache.Si­ngletonEhCacheRegionFactory</property> 

3) Finally I had to add slf4j-api-1.6.1.jar (I found it in ehcache-2.5.1-distribution.tar­.gz downloaded from ehcache.org in addition) because of ClassNotFoundException.

Także, jeśli nie zostało to zrobione już, dodać do swojej hibernate.cfg.xml:

<!-- Enable Hibernate's automatic session context management --> 
<property name="cache.use_second_level_cache">true</property> 

Kluczowym punktem było dodanie słoika ehcache z opcjonalnego katalogu \ w Hibernate4.

2

Dodaj następujące właściwości z właściwościami Hibernacja:

<prop key="hibernate.cache.use_second_level_cache">true</prop> 
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> 
<prop key="hibernate.cache.provider_configuration_file_resource_path">hibernate-ehcache.xml</prop> 
<prop key="hibernate.cache.use_query_cache">true</prop> 
<prop key="hibernate.generate_statistics">true</prop> 
<prop key="hibernate.cache.use_structured_entries">true</prop> 

Trzeba hibernate-ehcache 4.1.1 słoik lub nie ehcache jar.

Należy zanotować klasę dostawcy pamięci podręcznej, która uległa zmianie.

1

Nadzieję, że może się przydać komuś (hibernacja 4.x).

Wyciąg z mojego konfiguracji sprężyny:

public Properties hibernateProperties() { 
    Properties properties = new Properties(); 
    properties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); 
    properties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); 
    properties.setProperty("hibernate.format_sql", "true"); 
    properties.setProperty("hibernate.generate_statistics", env.getProperty("hibernate.generate_statistics")); 
    // second-level cache: 
    properties.setProperty("hibernate.cache.use_second_level_cache", "true");   
    properties.setProperty("hibernate.cache.region.factory_class", "org.hibernate.cache.EhCacheRegionFactory"); 
    properties.setProperty("net.sf.ehcache.configurationResourceName", env.getProperty("net.sf.ehcache.configurationResourceName")); 
    return properties; 
} 

Musisz mieć 'org.hibernate: hibernate-ehcache: HIBERNATE_VERSION' na ścieżce klas.

Zobacz: Ehcache doc on hibernate configuration

Powiązane problemy