INFO: HHH000041: Configured SessionFactory: null
出现SessionFactory: null为空的问题,不知道为什么,上网查了一下,可能是配置的问题,可是我检查了很久,没有觉得配置有问题丫,不知道为什么?大神求解?
出现SessionFactory: null为空的问题,不知道为什么,上网查了一下,可能是配置的问题,可是我检查了很久,没有觉得配置有问题丫,不知道为什么?大神求解?
2016-05-31
package com.imooc.util;
//创建HibernateUtil工具类,用以在程序中初始化hibernate,获得工厂和会话
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static SessionFactory sessionFactory;
private static Session session;
static{
//创建Configuration对象,读取hibernate.cfg.xml文件,完成初始化
Configuration config=new Configuration().configure();
//这个要导入hibernate4.3以上的包
StandardServiceRegistryBuilder ssrb=new StandardServiceRegistryBuilder().applySettings(config.getProperties());
StandardServiceRegistry ssr=ssrb.build();
sessionFactory=config.buildSessionFactory(ssr);
}
//获取SessionFactory
public static SessionFactory getSessionFactory(){
return sessionFactory;
}
//获取session
public static Session getSession(){
session=sessionFactory.openSession();
return session;
}
//关闭session
public static void closeSession(Session session){
if(session!=null){
session.close();
}
}
}
求解,我的配置是这样也有一样的问题,报的错误是:
INFO: HHH000041: Configured SessionFactory: null
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/hibernate/boot/registry/StandardServiceRegistryBuilder : Unsupported major.minor version 52.0后面那个说是版本的问题我用的jdk1.7 改成1.6运行也不行,难道要用1.8么?
举报