HibernateException: Could not obtain transaction-synchronized Session for current thread
2015-12-17 14:28
561 查看
使用hibernate4的SessionFactory获取Session时有两种方式
1、sessionFactory.getCurrentSession()
2、sessionFactory.openSession(),开启新session,需要关闭
当使用1获取CurrentSession,不会开启新的session,速度要快。但是如果你是使用多线程的时候,就不能使用getCurrentSession,这样会报以下错误
只需要改成openSession方式就可以解决了
1、sessionFactory.getCurrentSession()
2、sessionFactory.openSession(),开启新session,需要关闭
当使用1获取CurrentSession,不会开启新的session,速度要快。但是如果你是使用多线程的时候,就不能使用getCurrentSession,这样会报以下错误
org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
只需要改成openSession方式就可以解决了
相关文章推荐
- LeetCode Container With Most Water
- db2 优化基础 打开EXPLAIN
- “Could not find a storyboard named 'MainStoryboard' in bundle NSBundle” 的问题。
- You have new mail in /var/spool/mail/root 解决方法
- retain、copy、mutableCopy的区别(深拷贝 浅拷贝)
- poj 1273 Drainage Ditches
- 安卓开发之安卓AIDL的使用
- 安装并运行apk时出现恼人的"Error: Activity class {xxx/xxx.MainActivity} does not exist."
- wait,notify,notifyAll详细介绍
- GCD Again(杭电oj1787)(欧拉函数)
- JetBrains PyCharm 4.0.4 key
- Keepailved详细介绍
- SVN commit:remains in tree-conflict解决方案
- Raphael的Braille例子
- svn Aborting commit: 'XXX' remains in conflict 错误
- AIX下采用dd方式进行数据迁移的过程,供参考
- available()方法的讲解 .
- C++有哪几种情况只能用初始化列表,而不能用赋值?http://zhidao.baidu.com/link?url=omVOhkgo4ZtpRddk794ly-aX79VjboKv3c3noM5tdz
- Leetcode: Contains Duplicate II
- Leetcode: Contains Duplicate