空指针异常求大神指教
很郁闷试了好久还是错
很郁闷试了好久还是错
2016-07-07
一样的问题, 已解决。
hibernate换到最新的5.2.1
然后代码这样写
public class StudentTest {
private Configuration config ;
private SessionFactory sessionFactory;
private Session session;
private Transaction transaction;
@Before
public void init(){
config = new Configuration().configure();
sessionFactory = config.buildSessionFactory();
session = sessionFactory.openSession();
transaction = session.beginTransaction();
}
@Test
public void testSave(){
Student s = new Student(18, 16, "Lucy", new Date());
session.save(s);
}
@After
public void destory(){
transaction.commit();
session.close();
sessionFactory.close();
}
}
举报