您的位置:首页 > 大数据 > 人工智能

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,这样会报以下错误

org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread


只需要改成openSession方式就可以解决了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: