session问题

yhm2046 yhm2046 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
/**
* @description 向t_main_type表插入新类别 insert into t_main_type('mt00','类别名');
*/
public static boolean insert2MainType(MainType mainType) {
Session ses = null;
SessionFactory sf = null;
try {
Configuration cfg = new Configuration().configure();
sf = cfg.buildSessionFactory();//这句为什么过时了,有啥新的方法?
ses = sf.openSession();

Transaction trans = ses.beginTransaction();
ses.save(mainType);
trans.commit();
} catch (HibernateException e) {
System.out.println("exception-->" + e);
e.printStackTrace();
return false;
} finally {
// sf.close(); //为什么这里不能关闭,关闭就报错:Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor]
ses.close();
}
return true;
}
...全文
评论 8
收藏 已收藏
分享
返回顶部
yhm2046
Web 开发 81,108 成员 341,721 内容