2013年11月3日星期日

How to configure

hibernate secondary cache Test hibeinate secondary cache , hibernate 4.1.1 Myeclipse 8.6. Following exception :

at com.hsp.view.TestMain.main (TestMain.java: 28)
Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_classis not gaven, please either disable second level cache or set correct region factory class name to property hibernate.cache.region.factory_class (and make sure ; the second level cache provider, hibernate-infinispan, for example, available in the classpath).
at org.hibernate.cache.internal.NoCachingRegionFactory.buildEntityRegion (NoCachingRegionFactory.java: 69)
at org.hibernate.internal.SessionFactoryImpl. (SessionFactoryImpl.java: 347)
at org.hibernate.cfg.Configuration.buildSessionFactory (Configuration.java: 1740)
at org.hibernate.cfg.Configuration.buildSessionFactory (Configuration.java: 1778)
at com.hsp.util.HibernateUtil. (HibernateUtil.java: 23)
... 1 more

hibernate.cfg.xml as follows:




org.hibernate.dialect.Oracle9Dialect


jdbc: oracle: thin: @ 127.0.0.1:1521: orcl

scott
tiger

oracle.jdbc.driver.OracleDriver


myoralce

true
update


true
true

org.hibernate.cache.internal.EhCacheProvider








I found org.hibernate.cache.internal package does not EhCacheProvider this class, is the reason causing the problem ? There needs to be configured ehcache.xml file it, I did not configure .
------ Solution ---------------------------------------- ----
org.hibernate.cache.internal.EhCacheProvider
changed
org.hibernate.cache.EhCacheRegionFactory


------ For reference only ---------------------------------- -----


tried , the error is still the same . org.hibernate.cache.EhCacheRegionFactory class bag did not , I would package seems to have problems
------ For reference only ---------------- -----------------------
hibernate4.x modified after this , but the documentation that comes with the configuration file is not correct , I started to have encountered to this problem. org.hibernate.cache.internal.EhCacheProvider
changed :
org.hibernate.cache.ehcache.EhCacheRegionFactory
------ For reference only --- ------------------------------------
test is successful ! Thank you !
------ For reference only -------------------------------------- -
modified after the test is successful , but why should this change it ? Default settings and 4.1 documents which are org.hibernate.cache.internal.EhCacheProvider
------ For reference only - -------------------------------------
true -> I put a commented out , seems to have no problem, do not know where I am with the wrong ?
other code is as follows:
@ Entity
@ Cache (usage = CacheConcurrencyStrategy.READ_WRITE)
public class Student {......

/ / junit4 test code is as follows
@ Test
public void testCache2 () {
Session ss = HibernateUtil.getSession ();
ss.beginTransaction ();
Student s = (Student) ss.load (Student.class, 2);
System.out.println (s.getName ());
ss.getTransaction (). commit ();

Session ss2 = HibernateUtil.getSession ();
ss2.beginTransaction ();
Student s2 = (Student) ss2.load (Student.class, 2);
System.out.println (s2.getName ());
ss2.getTransaction (). commit ();
}

没有评论:

发表评论