Exception in thread "main" java.lang.ClassCastException: org.hibernate.transaction.JDBCTransaction cannot be cast to javax.transaction.Transaction
at ch12.hibernate.HibernateDatabaseDemo.main(HibernateDatabaseDemo.java:23)
源代码为:
SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
Userinfo user=new Userinfo();
user.setName("cheny");
user.setSex("M");
user.setAge(22);
Session session=sessionFactory.openSession();
Transaction trans=(Transaction) session.beginTransaction();//报错 session.save(user);
try {
trans.commit();
} catch (Exception e) {
e.printStackTrace();
}
------解决方案--------------------
包倒错了吧