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和当前线程绑定,在事务结束后会自动关闭。
sessionFactory中的openSession和getCurrentSession的一些注意事项的更多相关文章
- hibernate中openSession()跟getCurrentSession()方法之间的区别
Hibernate openSession() 和 getCurrentSession的区别 getHiberanteTemplate .getCurrentSession和OpenSession 采 ...
- Hibernate中openSession() 与 getCurrentSession()的区别
1 getCurrentSession创建的session会和绑定到当前线程,而openSession每次创建新的session. 2 getCurrentSession创建的线程会在事务回滚或事物提 ...
- HIbernate中openSession和getCurrentSession
这两者的差别网上非常多资源,我这里就copy一下了,然后有点问题的是今天遇到的问题. openSession和getCurrentSession的根本差别在于有没有绑定当前线程,所以,用法有差 ...
- openSession和getCurrentSession的比较
在比较openSession和getCurrentSession这两个方法之前,我们先认识一下这两个方法. 在进行配置信息管理时,我们一般进行一下简单步骤: Configuration cfg = n ...
- Hibernate之openSession与getCurrentSession的区别
openSession 与 getCurrentSession的区别(1)openSession 每一次获得的是一个全新的session对象,而getCurrentSession获得的是与当前线程绑定 ...
- hibernate3.6-联合主键注解以及openSession和getCurrentSession区别
[联合主键]>>>>配置方式:xml: 1. Student中单独创建StudentPk主键实体类 2. 配置: <composite-id name=" ...
- hibernate中session的获取使用以及其他注意事项
hibernate中session的获取使用以及其他注意事项 前言:工作时,在同时使用Hibernate的getSession().getHibernateTemplate()获取Session后进行 ...
- asterisk中使用dahdi通道呼出的注意事项
asterisk中使用dahdi通道呼出的注意事项 在使用dahdi通道呼出的时候,可以在Dial中对呼出所使用的通道进行指定选择.以下面的例子来说明: 场景说明:数字板卡单E1,使用pri信令,1- ...
- 微信公众号开发之网页中及时获取当前用户Openid及注意事项
目录 (一)微信公众号开发之VS远程调试 (二)微信公众号开发之基础梳理 (三)微信公众号开发之自动消息回复和自定义菜单 (四)微信公众号开发之网页授权获取用户基本信息 (五)微信公众号开发之网页中及 ...
随机推荐
- vue实现实时监听文本框内容的变化(最后一种为原生js)
一.用watch方法监听这个变量. <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
- Lab 10-1
This lab includes both a driver and an executable. You can run the executable from anywhere, but in ...
- koa源码之delegate使用
koa中context可以直接调用request和response属性的重要原因是使用了delegate将req和res的属性代理到context, Delegator.prototype.gette ...
- cef-3.2623 build on vs2013
1. 参文"在Windows下编译Cef3.2623并加入mp3.mp4支持(附带源码包和最终DLL)"下载包 http://blog.csdn.net/zhuhongshu/ar ...
- Python —— 函数高级特性(切片、迭代、列表生成式、生成器、迭代器)
一.切片(Slice) 在很多编程语言中,针对字符串提供了很多截取函数(i.e. substring),目的就是对字符串切片.python中没有针对字符串的截取函数,需要通过“切片”来完成. 取一个 ...
- OO的奇妙冒险2
OO的奇妙冒险 ~多线程入门与魔鬼的优化~ 目录 总体分析 作业内容分析 作业内容总结 互测的收获 公测互测bug分析与总结 优化分析 不太正经的个人自嗨 总体分析 公测 中测(基础与进阶): 这一单 ...
- vscode 中 eslint 相关配置
1.设置vue等文件有eslint提示 "eslint.validate": [ "javascript", "javascriptreact&quo ...
- samba及其基本应用
Samba 137/udp,138/udp,139/tcp,445/tcp windowns主机共享: linux主机进行访问查看资源:smbclient -L Server_IP -U 用户名 li ...
- tomcat 7 启动报错:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig()Ljavax/servlet/SessionCookieConfig的解决
现象: tomcat 7 启动报错:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig() ...
- js的回调函数
介绍首先从英文介绍开始 A callback is a function that is passed as an argument to another function and is execut ...