hibernate错误

[b]TEST CODE[/b]:package Hexample;

import java.util.Date;

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

public class HibernateTest {

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub

    Guestbook gb=new Guestbook();
    gb.setName("abc");
    gb.setEmail("habn@hotmail.com");
    gb.setPhone("142341");
    gb.setTitle("hello");
    gb.setContent("sfdsfsdfdsfsd");
    gb.setCreatedTime(new Date());

    Configuration config=new Configuration();
    config.configure(); 
    SessionFactory sessionFactory=config.buildSessionFactory();
    Session session=sessionFactory.getCurrentSession();
    Transaction tx=session.beginTransaction();
    session.save(gb);
    tx.commit();
    }}

[b]GUESTBOOK.HBM.XML[/b]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
package="Hexample">

<class name="Guestbook" table="GUESTBOOK" lazy="true">
    <comment>Users may bid for or sell auction items.</comment>
    <id name="id">
    <generator class="sequence">
    <param name="sequence" >gb_seq</param>
    </generator>
    </id>

    <property name="name" column="name" type="java.lang.String"></property>
    <property name="email" column="email" type="java.lang.String"></property>
    <property name="title" column="title" type="java.lang.String"></property>
    <property name="content" column="content" type="java.lang.String"></property>
    <property name="phone" column="phone" type="java.lang.String"></property>
    <property name="createdTime" column="created_time" type="java.util.Date"></property>

</class>


[b]配置文件[/b]
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<session-factory>

    <!-- Database connection settings -->
    <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
    <property name="connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
    <property name="connection.username">xuanyuanjian</property>
    <property name="connection.password">shixiaochen</property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">2</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>

    <!-- Enable Hibernate's current session context -->
    <property name="current_session_context_class">org.hibernate.context.ManagedSessionContext</property>

    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">thread</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>



    <mapping resource="Hexample/Guestbook.hbm.xml"></mapping>
</session-factory>

Exception in thread "main" org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge]
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:412)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:271)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
at Hexample.HibernateTest.main(HibernateTest.java:30)
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:513)
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:407)
... 4 more
Caused by: org.hibernate.cache.CacheException: could not instantiate CacheProvider [thread]
at org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge.(RegionFactoryCacheProviderBridge.java:66)
... 9 more
Caused by: java.lang.ClassNotFoundException: thread
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:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:123)
at org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge.(RegionFactoryCacheProviderBridge.java:63)
... 9 more
这个错误。。baidu无果 请各位大大帮小弟寻找解决之道 谢谢大家了

4个回答

hibernate.cfg.xml 配置有问题吧,
org.hibernate.context.ManagedSessionContext改为:
thread
删除<!-- Disable the second-level cache -->
thread

Session session=sessionFactory.getCurrentSession();
改成Session session=sessionFactory.openSession(); 行不行

或者Caused by: java.lang.ClassNotFoundException: thread
有没有忘了的jar包

是没有找到org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge

先把Hibernate3.jar装入类路径,然后在类路径下添加ehcache.xml。
cache.provider_class=org.hibernate.cache.EhCacheProvider

立即提问