testSaveStudent() 报空指针异常
一直报空指针异常,不知道怎么解决啊,纠结
一直报空指针异常,不知道怎么解决啊,纠结
2015-12-07
public class StudentsTest {
private SessionFactory sessionFactory;
private Session session;
private Transaction transcation;
@Before
public void init(){
//创建配置对象
Configuration config=new Configuration().configure();
//创建服务注册对象
ServiceRegistry serviceRegistry=new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
//创建会话工厂对象
sessionFactory=config.buildSessionFactory(serviceRegistry);
//会话对象
session=sessionFactory.openSession();
//开启事务
transcation=session.beginTransaction();
}
@After
public void destory(){
transcation.commit();//提交事务
session.close();
sessionFactory.close();
}
@Test
public void testSaveStudent(){
Students s=new Students(1,"张三丰","男",new Date(),"武当山");
session.save(s);
}
}
举报