为了账号安全,请及时绑定邮箱和手机立即绑定

报错,求大神告知错误!

http://img1.sycdn.imooc.com//5a7ea0660001514b07610156.jpg

显示上图的错误,但是不知道错在哪?谢谢告知


import java.util.Date;


import org.hibernate.Session;

import org.hibernate.SessionFactory;

import org.hibernate.Transaction;

import org.hibernate.cfg.Configuration;

import org.hibernate.service.ServiceRegistry;

import org.hibernate.service.ServiceRegistryBuilder;

import org.junit.After;

import org.junit.Before;

import org.junit.Test;


public class StudentsTest {


private SessionFactory sessionFactory;

private Session session;

private Transaction transaction;

@Before

public void init(){

//创建配置对象

Configuration config=new Configuration().configure();

//创建服务注册对象

ServiceRegistry serviceRegistry=new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();

//创建会话工厂对象

sessionFactory=config.buildSessionFactory(serviceRegistry);

//会话对象

session=sessionFactory.openSession();

//开启事务

transaction=session.beginTransaction();

}


@After

public void destroy(){

transaction.commit();

session.close();

sessionFactory.close();

}


@Test

public void testSaveStudents(){

//创建学生对象

Students s=new Students(1,"张三丰","男",new Date(),"武当山");

session.save(s);//保存对象到数据库

}


}


正在回答

2 回答

还是报错


0 回复 有任何疑惑可以回复我~

Configuration config = new Configuration();

config.configure();

加下面这一句试试

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

报错,求大神告知错误!

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信