分析 org.hibernate.HibernateException: No Session found for current thread

/**
     *
     * org.hibernate.HibernateException: No Session found for current thread
     * 分析:getCurrentSession()和当前事务有关系
     *
     * Spring hibernate 事务的流程
     *
     * 1.在方法开始之前
     *         ①.获取Session
     *         ②.把Session 和当前线程绑定,这样就可以在Dao中 使用SessionFactory 的
     *         getCurrentSession() 方法来获取Session 了
     *         ③.开启事务
     *
     * 2.执行业务方法
     *        1)出现异常
     *         ①.回滚事务
     *        2)正常结束
     *         ①.提交事务
     *         finally{
     *             ②.和当前线程绑定的Session解除绑定
     *             ③.关闭Session
     *         }
     *
     * 结论:
     *         只要使用getCurrentSession()来获取Session,则
     *         ①必须配置事务 
     *         ②必须在配置事务属性时,包含所有的业务方法

     */

时间: 2024-12-14 00:44:06

分析 org.hibernate.HibernateException: No Session found for current thread的相关文章

spring+hibernate整合:报错org.hibernate.HibernateException: No Session found for current thread

spring+hibernate整合:报错信息如下 org.hibernate.HibernateException: No Session found for current thread at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:106) at org.hibernate.internal.SessionFactoryImpl.getC

org.hibernate.HibernateException: No Session found for current thread

严重: Servlet.service() for servlet [annomvc] in context with path [/joyen-learning] threw exception [Request processing failed; nested exception is org.hibernate.HibernateException: No Session found for current thread] with root causeorg.hibernate.Hib

hibernate在使用getCurrentSession时提示no session found for current thread

大致错误片段 org.hibernate.HibernateException: No Session found for current thread at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97) 大致问题:hibernate在处理sessoin SessionFactory的getCurrentSession并不能保证在没有当前Se

关于spring3中No Session found for current thread!and Transaction的配置和管理(转)

今天我是特别的郁闷,本来项目做到一半,以前都好好的,结果下午就出现问题,苦逼的到现在才解决.它出现问题的时候都一声不坑, ,(天啦,现在才发现CSDN啥时候把QQ表情给整过来了)就在注册用户的时候,咦,后台发现咋SQL语句特么的不对劲,仔细一看数据根本就没有送到数据库去,只是简单的执行了一下查询操作,当时我就震惊了.首先就去看了Action是否没有写save方法,结果是没有任何错误.后来我再去再其他业务层是否也出现了问题,结果都能正常操作,让我哭笑不得.后来只能查配置.当时我就看到这两个配置是在

Hibernate4 No Session found for current thread

Hibernate4 与 spring3 集成之后, 如果在取得session 的地方使用了getCurrentSession, 可能会报一个错:“No Session found for current thread”, 这个错误的原因,网上有很多解决办法, 但具体原因的分析,却没有多少, 这里转载一个原理分析: SessionFactory的getCurrentSession并不能保证在没有当前Session的情况下会自动创建一个新的,这取决于CurrentSessionContext的实现

SSH2 No Session found for current thread原因

Hibernate4 与 spring3 集成之后, 如果在取得session 的地方使用了getCurrentSession, 可能会报一个错:"No Session found for current thread", 这个错误的原因,网上有很多解决办法, 但具体原因的分析,却没有多少, 这里转载一个原理分析: SessionFactory的getCurrentSession并不能保证在没有当前Session的情况下会自动创建一个新的,这取决于CurrentSessionConte

Hibernate4 No Session found for current thread原因

Hibernate4 与 spring3 集成之后, 如果在取得session 的地方使用了getCurrentSession, 可能会报一个错:“No Session found for current thread”, 这个错误的原因,网上有很多解决办法, 但具体原因的分析,却没有多少, 这里转载一个原理分析: SessionFactory的getCurrentSession并不能保证 在没有当前Session的情况下会自动创建一个新的,这取决于CurrentSessionContext的实

SpringMVC4+Hibernate4运行报错Could not obtain transaction-synchronized Session for current thread

查了一下相关资料,整理如下: 原因:Hibernate4 No Session found for current thread原因 解决方法: 1.  在spring 配置文件中加入  程序代码 <tx:annotation-driven transaction-manager="transactionManager"/> 并且在处理业务逻辑的类上采用注解  程序代码 @Service public class CustomerServiceImpl implements

org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not

遇到这个问题之前,我去百度和谷歌去搜索了一下,发现各种说法,但是针对我的项目而言,也就是公司的项目而言,这个问题的根源并非是网上所说的那样. 最后是通过自己的想法做测试得到了解决. 1.首先说说我的配置吧!我的配置是通过spring自带的注解来实现 声明式事物管理的.如果我们没去了解spring的声明式事物管理的话,或许我们是得不出什么结论的. 如果你配置过声明式事物管理,你就知道spring是怎么帮你管理的. 2.spring声明式事物管理是在service层管理的,关于到sessionFac