<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="create*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice> <aop:config proxy-target-class="true">
<aop:advisor advice-ref="txAdvice" pointcut="execution(* net.noday..service..*.*(..))" />
</aop:config>

getCurrentSession需要做如下配置:

<propertyname="current_session_context_class" >thread</property>

1. 前者打开一个新的,后者当前有session的话,则是使用当前的session,没有的话则创建一个新的;

2. 如果使用前者获得一个session的话,需要手动关闭session,使用后者,当事务提交,session会自动关闭,如果再关闭session则会报如下异常:Session has already closed;

3. sf.getCurrentSession方法需要在hibernate.cfg.xml做如下配置:

<propertynamepropertyname="current_session_context_class" >thread</property>

没有配置的话会报如下异常:org.hibernate.HibernateException:No CurrentSessionContext configured!

Spring framework3.2整合hibernate4.1报错:No Session found for current thread的更多相关文章

  1. Spring+Hibernate4 Junit 报错No Session found for current thread

    论坛上有另外一篇更全面的帖子,jinnianshilongnian写的:http://www.iteye.com/topic/1120924 本文的环境是:  spring-framework-3.1 ...

  2. Hibernate4集成spring4报错----No Session found for current thread

    在编写一个Hibernate4集成spring4的小demo的时候出现了该错误: org.hibernate.HibernateException: No Session found for curr ...

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

    spring+hibernate整合:报错信息如下 org.hibernate.HibernateException: No Session found for current thread at o ...

  4. spring 整合Mybatis 《报错集合,总结更新》

    错误:java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldExcepti ...

  5. 【spring boot】spring cloud下spring boot微服务启动没有报错,但是访问访问不到

    spring cloud下spring boot微服务启动没有报错,但是访问访问不到 解决方法: 可能是端口被占用了,但是依旧启用成功了. 更改一下项目启用的端口号,再重新启动查看是否可以正常访问.

  6. Bug集锦-Spring Cloud Feign调用其它接口报错

    问题描述 Spring Cloud Feign调用其它服务报错,错误提示如下:Failed to instantiate [java.util.List]: Specified class is an ...

  7. 关于子线程使用Toast报错Can't create handler inside thread that has not called Looper.prepare()的解决办法

    形同如下代码,在Thread中调用Toast显示错误信息: new Thread(new Runnable(){ @Override public void run() { try{ weatherD ...

  8. Hibernate4 No Session found for current thread原因

    Hibernate4 与 spring3 集成之后, 如果在取得session 的地方使用了getCurrentSession, 可能会报一个错:“No Session found for curre ...

  9. Hibernate4 No Session found for current thread

    Hibernate4 与 spring3 集成之后, 如果在取得session 的地方使用了getCurrentSession, 可能会报一个错:“No Session found for curre ...

随机推荐

  1. java基础-面向对象的思想

    一.什么是面向对象 面向对象是一种思想,在java中通常我们会说一句话一切事物即对象.而面向对象到底是怎么回事呢?这里我从人们对问题的思考来阐述,人在思考的一个问题的时候比如在解决一个数学问题的时候我 ...

  2. 撩课-Java每天5道面试题第19天

    126.Struts2中的拦截器有什么用?列举框架提供的拦截器名称? )拦截器是struts2核心组成部分, 它提供了一种机制,使得开发者 可以定义一个特定的功能模块, 这个模块会在Action执行之 ...

  3. windows 格式化D盘

    格式化D盘1.右击我的电脑2.高级系统设置3.高级4.性能->设置5.高级->虚拟内存(更改)6.双击D设置->无分页文件7.确定->重启计算机

  4. BOM(JavaScript高程笔记)

    再次编辑于20160115 一.window对象 双重角色 JS访问浏览器窗口的接口 ECAMAscript规定的Global对象 1.全局作用域 所有在全局作用域中声明的变量.函数都会变成windo ...

  5. python-代理模式

    源码地址:https://github.com/weilanhanf/PythonDesignPatterns 说明: 模式动机 通过引入一个新的对象(如小图片和远程代理对象)来实现对真实对象的操作或 ...

  6. python正则表达式贪婪与非贪婪模式

    之前做程序的时候看到过正则表达式的贪婪与非贪婪模式,今天用的时候就想不起来了,现在这里总结一下,以备自己以后用到注意. 1.什么是正则表达式的贪婪与非贪婪匹配 如:String str="a ...

  7. 洛谷P4198 楼房重建(线段树)

    题意 题目链接 Sol 别问我为什么发两遍 就是为了骗访问量 这个题的线段树做法,,妙的很 首先一个显然的结论:位置\(i\)能被看到当且仅当\(\frac{H_k}{k} < \frac{H_ ...

  8. element-ui Tag、Dialog组件源码分析整理笔记(五)

    Tag 标签组件 <script> export default { name: 'ElTag', props: { text: String, closable: Boolean, // ...

  9. php判断是不是移动设备

    <?php function isMobile() {     // 如果有HTTP_X_WAP_PROFILE则一定是移动设备     if (isset ($_SERVER['HTTP_X_ ...

  10. RecyclerView源码解析 - 分割线

    猜想:   既然考虑了分割线,那么子View在测量时候肯定要去考虑分割线留出的位置    直接measureChild()方法 猜想: 分割线会调用绘制的方法 onDraw()