package entity; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.service.*; import org.hibernate.tool.hbm2ddl.SchemaExport; import org.junit.Test; public class TestStudents { @Test public void testSchemaExport() { //创建配置对象 Configuration config = new Configuration().configure(); ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry(); //创建sessionfactory SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry); //创建Session对象 Session session = (Session) sessionFactory.getCurrentSession(); //创建SchemExport SchemaExport export = new SchemaExport(config); export.create(true,true); } }
private static SessionFactory sessionFactory;
private MyHibernateSessionFactory(){
}
public static SessionFactory getSessionFactory(){
if(sessionFactory==null){
Configuration config=new Configuration().configure();
ServiceRegistry serviceRegistry =new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
sessionFactory=config.buildSessionFactory(serviceRegistry);
return sessionFactory;
}else {
return sessionFactory;
}
sessionFactory为什么过不去?
用junit报错了,这是什么情况啊,求大神帮忙
我的也报错了,把//创建sessionFactory
// SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
//创建session对象
// Session session = sessionFactory.getCurrentSession();注释掉就正确了 不知道什么情况
把报错整个贴出来一下才能看到。可能是hibernate.cfg.xml文件里的
<mapping resource="entity/Students.hbm.xml"/>
<mapping resource="entity/Users.hbm.xml"/>
配置有误。