-->
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.  [ 4 posts ] 
Author Message
 Post subject: Second Level cache with EHCACHE provider
PostPosted: Sun Sep 13, 2009 8:37 am 
Newbie

Joined: Sun Sep 13, 2009 8:27 am
Posts: 2
i am getting error stack below,when i am implementing Second Level Cache with EcCacheProvider

eccache.xml
<ehcache>

<diskStore path="java.io.tmpdir"/>


<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
/>
<cache name="com.hibernate.pojo.employee"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="true"
/>


<!-- Place configuration for your caches following -->

</ehcache>

hibnerate.cfg.xml:

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


<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/YYY</property>
<property name="connection.username">root</property>
<property name="connection.password">XXXX</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.pool_size">10</property>

<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>


<property name="hibernate.transaction.auto_close_session">true</property>
<property name="hibernate.generate_statistics ">true</property>
<property name="hibernate.cache.region_prefix">arYYk</property>
<property name="hibernate.connection.autocommit">true</property>

<property name="hibernate.cache.provider_class">org.hibernate.cache.EHCacheProvider</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>

<mapping resource="hbm/employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>

package org.hibernate.sample.examples;

import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.hibernate.factory.HibernateUtil;
import com.hibernate.pojo.Employee;

public class HibernateCache {

/**
* @param args
*/
public static void main(String[] args) {
queryCache();

}

private static void queryCache() {
Transaction tran =null;
try
{
Session session = HibernateUtil.getInstance().getSession();
tran=session.beginTransaction();
tran.begin();
Query query = session.createQuery(" from Employee ");
// query.setString(0, "Hibernate");
List list = query.list();

query.setCacheable(true);

Iterator< Employee> it=list.iterator();
while(it.hasNext())
{
Employee employee =it.next();
System.out.println(employee.getEmpid() + " "+employee.getEname());
}


tran.commit();


}catch(Exception ee)
{
tran.rollback();
ee.printStackTrace();

}


}

}

HibernateUtil.java:

package com.hibernate.factory;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
private static SessionFactory sessionFactory = null;
private static HibernateUtil hibernateFactory = null;
static
{
try
{
sessionFactory = new Configuration().configure().buildSessionFactory();
}catch(HibernateException e)
{
e.printStackTrace();
System.out.println("Error while creating Session Factory");
}
}
public SessionFactory getSessionFactory()
{
return sessionFactory;
}
private HibernateUtil()
{

}
public Session getSession()
{
try
{
return sessionFactory.openSession();
}catch(Exception e)
{
System.out.println("Error while create Session"+e);
return null;
}
}

public void closeSession(Session session)
{
try
{
if(session !=null)

session.close();

}catch(HibernateException e)
{
System.out.println(" ******** Error while closing Session"+e);
}
}
public static HibernateUtil getInstance()
{
if(hibernateFactory == null)
hibernateFactory = new HibernateUtil();
return hibernateFactory;
}

public Session getSession(String file)
{
try
{
SessionFactory configSessionFactory = new Configuration().configure(file).buildSessionFactory();
return configSessionFactory.openSession();
}catch(HibernateException hibernateException)
{
System.out.println("Error while creating session"+hibernateException);
return null;
}
}
}

employee.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!--
This mapping demonstrates content-based discrimination for the
table-per-hierarchy mapping strategy, using a formula
discriminator.
-->

<hibernate-mapping
package="com.hibernate.pojo">
<class name="Employee" table="employee">

<cache usage="read-write"/>
<id name="empid" type="int" unsaved-value="0" >
<generator class="increment"/>
</id>
<property name="ename"/>
</class>

<!--
<query name="ByNameAndMaximumWeight">
<![CDATA[ from employee] ]>
</query> -->

</hibernate-mapping>



Error :
31 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
47 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
47 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
62 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
234 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
234 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
749 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : hbm/employee.hbm.xml
921 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: com.hibernate.pojo.Employee -> employee
968 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
1093 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
1093 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 10
1093 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: true
1108 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://127.0.0.1:3306/ark
1108 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=root, password=****, autocommit=true}
1732 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: MySQL, version: 5.1.28-rc-community
1732 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.3-rc ( Revision: ${svn.Revision} )
1795 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
1795 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
1796 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
1796 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
1796 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: enabled
1796 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
1796 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
1796 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
1796 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
1796 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
1796 [main] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
1796 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
1796 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
1796 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
1796 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
1796 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
1796 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
1796 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
1796 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
1796 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
1796 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: enabled
1796 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
1796 [main] INFO org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge - Cache provider: org.hibernate.cache.EHCacheProvider
org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge]
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:389)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:262)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
at com.hibernate.factory.HibernateUtil.<clinit>(HibernateUtil.java:15)
at org.hibernate.sample.examples.HibernateCache.queryCache(HibernateCache.java:27)
at org.hibernate.sample.examples.HibernateCache.main(HibernateCache.java:19)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:384)
... 7 more
Caused by: org.hibernate.cache.CacheException: could not instantiate CacheProvider [org.hibernate.cache.EHCacheProvider]
at org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge.<init>(RegionFactoryCacheProviderBridge.java:66)
... 12 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.cache.EHCacheProvider
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge.<init>(RegionFactoryCacheProviderBridge.java:63)
... 12 more
Error while creating Session Factory
Error while create Sessionjava.lang.NullPointerException
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.sample.examples.HibernateCache.queryCache(HibernateCache.java:66)
at org.hibernate.sample.examples.HibernateCache.main(HibernateCache.java:19)


Last edited by ramakrishna1721982 on Sun Sep 13, 2009 3:59 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Second Level cache with EHCACHE provider
PostPosted: Sun Sep 13, 2009 10:35 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
What line of code is triggering this error?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: Second Level cache with EHCACHE provider
PostPosted: Sun Sep 13, 2009 4:02 pm 
Newbie

Joined: Sun Sep 13, 2009 8:27 am
Posts: 2
Cameron McKenzie wrote:
What line of code is triggering this error?


i am posted complete code for implementating Second Level cache with EHCaheProvider........


Top
 Profile  
 
 Post subject: Re: Second Level cache with EHCACHE provider
PostPosted: Thu Sep 17, 2009 6:00 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
It can't find the EhCacheProvider class name.

You have EHCacheProvider not EhCacheProvider.

Caused by: java.lang.ClassNotFoundException: org.hibernate.cache.EHCacheProvider
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.