sessionFactory中的openSession和getCurrentSession的一些注意事项

今天进行Hibernate测试时遇到了一个问题

我在用sessionFactory生产seesion时出现了故障,使用getCurrentsesstion时产生异常:

Exception in thread "main" org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread

应该是说在主线程中不能包含事务同步会话

参考链接:

https://blog.csdn.net/wang1472jian1110/article/details/42679217

http://www.360doc.com/content/11/0502/19/987036_113784420.shtml

优先推荐:https://blog.csdn.net/lmdcszh/article/details/13775933

相同点

    openSession与getCurrentSession都可以创建session

不同点

    * openSession没有绑定当前线程,所以,使用完后必须关闭,

    * currentSession和当前线程绑定,在事务结束后会自动关闭。

转载于:https://www.cnblogs.com/Sword007/p/10624650.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值