运行test类出现java.lang.Exception:No runnable method;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import studentDAO.Student;
public class StudentTest {
private SessionFactory sessionFactory;
private org.hibernate.Session session;
private Transaction transaction;
@Before
public void init(){
Configuration config = new Configuration().configure();//config为配置对象
sessionFactory = config.buildSessionFactory();//创建会话工厂
session = sessionFactory.openSession();
transaction = session.beginTransaction();//事物
}
@After
public void destroy(){
transaction.commit();//提交事物
session.close();//关闭会话
sessionFactory.close();//关闭工厂
}
@Test
public void testSaveStudent(){
Student student = new Student(1, "张三", "男", new Date(), "喜马拉雅");
session.save(student);
}
}