Spring 3.2.2 与Hibernate 4.3.5 集成(事务交给Spring管理)

配置:

<span style="font-family: Arial, Helvetica, sans-serif;"><prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop></span>

然后用sessionFactory.getCurrentSession()时会出现org.hibernate.HibernateException: No CurrentSessionContext configured!的异常

然后先百度后google,大部分都是说将org.springframework.orm.hibernate4.SpringSessionContext改为thread或将sessionFactory.getCurrentSession()改为sessionFactory.openSession(),但那样做就没法用spring来管理hibernate的事务了,根本不可取

最后以为是事务没配置好,但手动添加事务后仍然报这个错,最后没辙,自己在获取session时用

SpringSessionContext ssc = new SpringSessionContext((SessionFactoryImplementor) this.sessionFactory);
Session cs = ssc.currentSession();

初始化一个session,这里不报CurrentSessionContext configured这个错了,但出现新的异常:java.lang.NoClassDefFoundError: org/hibernate/service/jta/platform/spi/JtaPlatform,最后查了下原来hibernate-core-4.3.5.Final.jar中没有jta包,我下载的源码中有jta,jar中竟然没有,有点吭爹,看来官网的东西也不是百分百靠谱,最后把hibernate-core-4.3.5.Final.jar替换成hibernate-core-4.2.15.Final.jar换回原来的方法就正常了

转载请注明出处http://blog.csdn.net/lt_1029/article/details/38084651,谢谢!


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值