"could not instantiate CacheProvider: net.sf.ehcache.hibernat" is the message thay I receive when trying to run the following code:
Code:
package com.hibernate.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.List;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
public class HibernateTestMain {
public static void main(String[] args) {
try {
HibernateTest ht = new HibernateTest("First Test");
}
catch(Exception e) {
System.out.println("[Error]: " + e.getMessage());
}
}
}
The HibernateTest class is as follows:
Code:
package com.hibernate.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.List;
import junit.framework.TestCase;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
public class HibernateTest extends TestCase
{
private Session session;
private Department department;
private Employee manager;
private static final int employeeId = 512;
private static final int departmentId = 444;
private Employee employee;
private static SessionFactory sessionFactory;
static {
try
{
Configuration cfg = new Configuration();
cfg.addClass(com.hibernate.test.Employee.class);
cfg.addClass(com.hibernate.test.Department.class);
sessionFactory = cfg.buildSessionFactory();
}
catch (Exception e)
{
//throw new RuntimeException("couldn't get connection");
System.out.println("[Error]: " + e.getMessage());
}
}
public HibernateTest(String testName)
{
super(testName);
}
public void setUp() throws Exception
{
...
}
public void testCreateAndReadDepartment() throws Exception
{
...
}
public void testCreateAndReadEmployee() throws Exception
{
...
}
public void testUpdateEmployeeSameSession() throws Exception
{
...
}
public void testUpdateEmployeeNewSession() throws Exception
{
...
}
public void testQuery() throws Exception
{
...
}
private static void wipeDatabase() throws Exception
{
...
}
}
The hibernate.properties file is as follows: (IBM DB2 8.1)
hibernate.connection.driver_class = COM.ibm.db2.jdbc.app.DB2Driver
hibernate.connection.url = jdbc:db2:BANKDATA
hibernate.connection.username = prnicn
hibernate.connection.password = pentagon
hibernate.dialect = net.sf.hibernate.dialect.DB2Dialect
The stack trace is as follows:
Code:
[INFO] Environment - -Hibernate 2.1.1
[INFO] Environment - -loaded properties from resource hibernate.properties: {hibernate.connection.username=prnicn, hibernate.connection.password=pentagon, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.DB2Dialect, hibernate.connection.url=jdbc:db2:BANKDATA, hibernate.connection.driver_class=COM.ibm.db2.jdbc.app.DB2Driver}
[INFO] Environment - -using CGLIB reflection optimizer
[INFO] Environment - -JVM does not support LinkedHasMap, LinkedHashSet - ordered maps and sets disabled
[INFO] Environment - -using workaround for JVM bug in java.sql.Timestamp
[INFO] Configuration - -Mapping resource: com/hibernate/test/Employee.hbm.xml
[INFO] Binder - -Mapping class: com.hibernate.test.Employee -> employee
[INFO] Configuration - -Mapping resource: com/hibernate/test/Department.hbm.xml
[INFO] Binder - -Mapping class: com.hibernate.test.Department -> department
[INFO] Configuration - -processing one-to-many association mappings
[INFO] Configuration - -processing one-to-one association property references
[INFO] Configuration - -processing foreign key constraints
[INFO] Dialect - -Using dialect: net.sf.hibernate.dialect.DB2Dialect
[INFO] SettingsFactory - -Use outer join fetching: true
[INFO] DriverManagerConnectionProvider - -Using Hibernate built-in connection pool (not for production use!)
[INFO] DriverManagerConnectionProvider - -Hibernate connection pool size: 20
[INFO] DriverManagerConnectionProvider - -using driver: COM.ibm.db2.jdbc.app.DB2Driver at URL: jdbc:db2:BANKDATA
[INFO] DriverManagerConnectionProvider - -connection properties: {user=prnicn, password=pentagon}
[INFO] TransactionManagerLookupFactory - -No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
[INFO] SettingsFactory - -Use scrollable result sets: true
[INFO] SettingsFactory - -Query language substitutions: {}
[INFO] SettingsFactory - -cache provider: net.sf.ehcache.hibernate.Provider
[Error]: could not instantiate CacheProvider: net.sf.ehcache.hibernate.Provider