org.hibernate.HibernateException:
2015-12-11 17:20
281 查看
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
这句话显而易见,就是事务没有的到spring管理,
设句话引起的。
主流的事物配置有两种:
1.注解模式@Transactional
解决方案:
检查springMVC中的配置
报出的错误与发生错误的位置完全没有关系,真是不理解,哪位大神明白原理请留言
这句话显而易见,就是事务没有的到spring管理,
public Session getSession (){ return this.sessionFactory.getCurrentSession(); }
设句话引起的。
主流的事物配置有两种:
1.注解模式@Transactional
<span style="white-space:pre"> </span><!-- 配置事务 --> <bean id="trManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 使用注解,在Service层的类上添加@Transcational() --> <tx:annotation-driven transaction-manager="trManager" proxy-target-class="true" />2.名称过滤模式
<!-- 事务管理 --> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 事务策略 --> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" rollback-for="java.lang.Exception" /> <tx:method name="delete*" propagation="REQUIRED" no-rollback-for="java.lang.Exception" /> <tx:method name="update*" propagation="REQUIRED" rollback-for="java.lang.SQLException" /> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice> <!-- aop映射 --> <aop:config> <aop:pointcut id="fooServiceOperation" expression="execution(* com.ldh.service.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceOperation" /> </aop:config>如果以上配置你都正确了,第一种模式也加上了,@Transactional;那么你要注意一个无厘头的问题。也是本文的结局方案
解决方案:
检查springMVC中的配置
<!-- 注解扫描包 --> <context:component-scan base-package="com.ldh.core.action" />这个配置中base-package只能扫描,包下面的类,包下面的包中的类似扫描不到的,所以你要注意,你所有的controller必须在这下面。
报出的错误与发生错误的位置完全没有关系,真是不理解,哪位大神明白原理请留言
相关文章推荐
- ARM寄存器
- redis研究之watch
- gulp教程之gulp-less
- Android项目开发技巧--moveTaskToBack(boolean ) 方法的使用
- LVM是逻辑盘卷管理1
- HDU 2299 归并求逆序
- HDOJ 2020 绝对值排序
- 常用电声器件的业余检测
- ARM伪指令
- 49 You enable block change tracking. You issue the following command: BACKUP INCREMENTAL LEVEL 0 DAT
- 如何编写一个程序猿另一个面试官眼前一亮的简历
- 第一次经历黑客攻击服务器系统
- Scrum Meeting NO.3
- 9个非常棒的Android代码编辑器 移动开发者的最爱
- 高精度
- 百宝云Post与Get事件教程
- 拷贝控制示例
- JSON API免费接口
- ARM寻址方式
- BeautifulSoup win+linux 安装配置