<?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"><!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>
    <session-factory>
        <property name="connection.username">root</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/user</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="myeclipse.connection.profile">mysql</property>
        <property name="connection.password">xxmi.com</property>
        <property name="connection.pool_size">100</property>
        <property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
        <!-- Mapping files -->
        <mapping resource="model.hbm.xml"/>
    </session-factory>
</hibernate-configuration>
这是hibernate.cfg.xml配置文件~

解决方案 »

  1.   

    我发现connection.driver_class属性写错了~
    但我改了过来还是报java.lang.ExceptionInInitializerError
    这个错误~??
      

  2.   

    这是我写的HibernateUtil.java
    import org.hibernate.HibernateException;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;public class HibernateUtil {
    private static Log log = LogFactory.getLog(HibernateUtil.class); private static final SessionFactory sessionFactory; static {
    try {
    // Create the SessionFactory
    sessionFactory = new Configuration().configure().buildSessionFactory();
    } catch (Throwable ex) {
    ex.printStackTrace();
    //log.error("Initial SessionFactory creation failed.", ex);
    throw new ExceptionInInitializerError(ex);
    }
    }
    public static final ThreadLocal session = new ThreadLocal();
    public static Session currentSession() throws HibernateException {
    Session s = (Session) session.get();
    // Open a new Session, if this Thread has none yet
    if (s == null||!s.isOpen()) {
    s = sessionFactory.openSession();
    session.set(s);
    }
    return s;
    }
    public static void closeSession() throws HibernateException {
    Session s = (Session) session.get();
    session.set(null);
    if (s != null)
    s.close();
    }
    }