hibernate的异常 Session was already closed
今天写hibernate时候遇到一些异常
代码:
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
session.save(t);
session.getTransaction().commit();
session.close();
System.out.println(t.getId());
出现异常情况:
出现以上原因是Session关闭
如果不是使用的SessionFactory.getSession()来获得Session。
而是使用SessionFactory.getCurrentSession()方法来获得Session时,当事务结束的时候,不管是提交还是回滚事务,hibernate会自动关闭Session的,
所以不需要手动关闭。
hibernate的异常 Session was already closed的更多相关文章
- org.hibernate.LazyInitializationException...no session or session was closed
org.hibernate.LazyInitializationException:failed to lazily initialize a collection of role:cn.its.oa ...
- hibernate报错org.hibernate.SessionException: Session was already closed
org.hibernate.SessionException: Session was already closedat org.hibernate.internal.SessionImpl.clos ...
- SSH dao层异常 org.hibernate.HibernateException: No Session found for current thread
解决方法: 在 接口方法中添加 事务注解 即可. public interface IBase<PK extends Serializable, T> { @Transactional v ...
- 【转】Hibernate 常见异常
转载地址:http://smartan.iteye.com/blog/1542137 Hibernate 常见异常net.sf.hibernate.MappingException 当出 ...
- Hibernate 常见异常
Hibernate 常见异常net.sf.hibernate.MappingException 当出现net.sf.hibernate.MappingException: Error r ...
- org.hibernate.HibernateException: No Session found for current thread
spring.springmvc和hibernate整合 在sessionFactory.getCurrentSession()时,出现以下异常 No Session found for curren ...
- 分析 org.hibernate.HibernateException: No Session found for current thread
/** * * org.hibernate.HibernateException: No Session found for current thread * 分析:ge ...
- 关于 org.hibernate.TransientObjectException 异常
在Hibernate的关联关系中,如果一个对象A 持有 对象 B 的引用,如果先保存 A ,再保存B,那么会出现 org.hibernate.TransientObjectException 异常. ...
- (八) Hibernate中的Session以及事务
HibernateUtil.getSessionFactory().getCurrentSession() 和HibernateUtil.getSession() 的区别: 1.异:getCurren ...
随机推荐
- php常量PHP_EOL
换行符 unix系列用 \n windows系列用 \r\n mac用 \r PHP中可以用PHP_EOL来替代,以提高代码的源代码级可移植性 如: <?php echo PHP_EOL; // ...
- 我的主机是win 7 虚拟机是vmware,solaris10连接主机
进入主机Control Panel—Administrative Tool—Services,打开服务Vmware DHCP Servise和Vmware NAT Service,启动后虚拟机上网正常 ...
- JS怎么把字符串数组转换成整型数组
今天在学习highcharts时,遇到了一个把字符串数组转换为整形数组的问题,拿在这里讨论一下: 比如有一个字符串: var dataStr="1,2,3,4,5"; 现在需要把它 ...
- golang之配置环境
从https://golang.org/dl/下载相关包,直接解压 目录大概这样 golang ├── go └── mods 配置环境变量 vim ~/.profile(debian需要勾选shel ...
- PHP-redis api 中文说明(转)
来源 : http://hi.baidu.com/gaolamp/item/1686aac07334bd0f0ad93a9f PHP-redis api 中文说明 phpredis 是 php 的一个 ...
- 【C#】datetimepicker里面如何设置日期为当天日期,而时间设为0:00或23:59?
今天无意中发现要根据日期查询时间,datatimepicker控件会把时间默认成当前时间(当你的控件只显示日期时),这样查询出来的出来的数据会有误差,用来下面的办法成功设置日期为当天日期,而时间设为0 ...
- Bootstrap table的一些简单使用总结
在GitHub上Bootstrap-table的源码地址是:https://github.com/wenzhixin/bootstrap-table Bootstrap-table的文档地址:http ...
- Shell 定时发送邮件检查网站脚本/邮件正文
#!/bin/bash ############################################################## # File Name: check_http.s ...
- TACACS+简单说明
1 TACACS+概述 1.1 什么是TACACS+ TACACS+(Terminal Access Controller Access Control System,终端访问控制器控制系统协议)是在 ...
- 第10课 struct 和 union 分析
1. struct的小秘密 (1)C语言中的struct可以看作变量的集合 (2)struct的问题——空结构体占用多的内存? [实例分析]空结构体的大小 #include <stdio.h&g ...