楼上的大哥你干脆告诉我怎么做能解决这个问题吧 我刚刚开始学习hibernate 不是很清楚你说的 谢谢

解决方案 »

  1.   

    换为以下内容试一下:
    <session-factory> 
    <property name="connection.username">root </property> 
    <property name="connection.url"> 
    jdbc:mysql://localhost:3306/test 
    </property> 
    <property name="dialect"> 
    org.hibernate.dialect.MySQLInnoDBDialect
    </property> 
    <property name="myeclipse.connection.profile"> 
    mysql 
    </property> 
    <property name="connection.password"> 
    gf851012 
    </property> 
    <property name="hibernate.connection.driver_class"> 
    com.mysql.jdbc.Driver 
    </property> 
    <property name="show_sql">true </property> 
    <mapping resource="com/hibernate/dao/Events.hbm.xml" /> 
    </session-factory> 
      

  2.   

    <property name="connection.user">
    用户名没有配置!
    </property> hibernate.cfg.xml不能在src下面放着!
    要放到classpath的路径下面,就是编译好的类路径下面,才能读取到!!!
      

  3.   

    驱动是否加入到classpath中
    hibernate.cfg.xml一般是放在src的根目录下,编译后在在输入的根目录下应该也要有,不然加载不到
    config.addClass(XXX.class);//自己指定.class文件
      

  4.   

    用eclipse的话就可以放置在src下,eclipse编译java的时候copy其他非java文件
    其他ide有些需要设置。
    楼主检查下 放class的地方是否有文件,同时检查配置,你用myeclipse自动生成的吧。
    你的sessionfactory如何加载的?
      

  5.   

    <?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"><hibernate-configuration>
    <session-factory>
    <property name="connection.username">root</property>
    <property name="connection.url">
    jdbc:mysql://localhost:3306/test
    </property>
    <property name="dialect">
    org.hibernate.dialect.MySQLDialect
    </property>
    <property name="myeclipse.connection.profile">mysql</property>
    <property name="connection.password">king</property>
    <property name="hibernate.connection.driver_class">
    com.mysql.jdbc.Driver
    </property> <!-- <property name="hibernate.connection.datasource">java:/comp/env/jdbc/store</property> -->
    <!-- <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
    <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
    <property name="connection.username">store</property>
    <property name="connection.password">store</property>
    <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property> -->
    <property name="show_sql">true</property>
    <!-- <mapping resource="cn/hibernate/trade_sort.hbm.xml" />
    <mapping resource="cn/hibernate/merchandise.hbm.xml" />
    <mapping resource="cn/hibernate/stocklist.hbm.xml" />
    <mapping resource="cn/hibernate/measureUnit.hbm.xml" /> -->
    </session-factory>
    </hibernate-configuration>
    在用这个测试一下
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;public class Hibernate_session {

    private static SessionFactory hibernateSessionFactory;

    private static Session hibernateSession;

    private static ThreadLocal<Session> localSession = new ThreadLocal<Session>();

    static{
    hibernateSessionFactory = new Configuration().configure("/hibernate.xml").buildSessionFactory();
    }

    public static Session getHibenateSession(){
    if(localSession.get()==null){
    hibernateSession = hibernateSessionFactory.openSession();
    localSession.set(hibernateSession);
    return hibernateSession;
    }
    else{
    return localSession.get();
    }
    }
    public static void closeSession(){
    if(localSession.get()!=null){
    localSession.set(null);
    }
    }
    public static void main(String []str){

    Session sission = getHibenateSession();
    System.out.println(sission.connection());
    }}看看创建链接是否成功
      

  6.   

    1:驱动JAR有没有在环境变量里
    2:从org.hibernate.HibernateException: Hibernate Dialect must be explicitly set 可以推断,根本咩有读取到你的配置信息
    3:把你的测试类贴出来
      

  7.   

    我用Eclipse3.4配置Hibernate ,报错:org.hibernate.connection.UserSuppliedConnectionProvider - No connection properties specified - the user must supply JDBC connections
    ,然后把配置文件放到class下居然好了。谢谢。