hibernate.dialect' must be set when no Connection available错误

初学hibernate ,今天试了一个例子但是报错 

org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available

package bijian.util;

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

public class HibernateUtil {
    private static SessionFactory sessionFactory;
    static{
    	try{
        	sessionFactory=new Configuration().buildSessionFactory();
        }catch(Throwable ex){
        	ex.printStackTrace();
        }
    }
    
    private static final ThreadLocal session=new ThreadLocal();
    public static Session getCurrentSession(){
    	Session s=(Session)session.get();
    	if(s==null){
    		s=sessionFactory.openSession();
    		session.set(s);
    	}
    	return s;
    }
    public static void closeSession(){
    	Session s=(Session)session.get();
    	if(s!=null){
    		s.close();
    	}
    	session.set(null);
    }
}
最终发现是     sessionFactory=new Configuration().buildSessionFactory();

new Configuration()默认是读取hibernate.properties


new Configuration().configure()来读取hibernate.cfg.xml文件

sessionFactory=new Configuration().configure().buildSessionFactory();


版权声明:本文为jazywoo123原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。