SSH整合开发之异常:No Session found for current thread
来源:互联网 发布:im源码 编辑:程序博客网 时间:2024/06/04 19:14
一、异常
org.hibernate.HibernateException: No Session found for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:106)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)
at cn.lzf.shopping.dao.BaseDaoHibernate.find(BaseDaoHibernate.java:62)
at cn.lzf.shopping.dao.BaseDaoHibernate.findAll(BaseDaoHibernate.java:47)
at cn.lzf.shopping.service.GoodServiceImpl.findAll(GoodServiceImpl.java:24)
at cn.lzf.shopping.action.GoodAction.getAllGoods(GoodAction.java:42)
二、异常分析
这是在用Spring整合Hibernate时出现的问题,在DAO内部是通过下列方式来存取数据的:
public class BaseDaoHibernate<T> implements BaseDao<T>{ private SessionFactory sessionFactory; @SuppressWarnings("unchecked") @Override public T get(Class<T> entityClazz, Serializable id) { return (T) getSessionFactory().getCurrentSession().get(entityClazz, id); //省略部分代码}
里面没有涉及到事务有关的代码,所以我们还需要对事务进行声明:
<!-- 配置事务增强处理 Bean --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="*" isolation="DEFAULT" propagation="REQUIRED" timeout="5" /> </tx:attributes> </tx:advice> <!-- AOP配置的元素 --> <aop:config> <aop:pointcut expression="execution(* cn.lzf.shopping.service.*.*(..))" id="myPointcut" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="myPointcut" /> </aop:config>
阅读全文
0 0
- SSH整合开发之异常:No Session found for current thread
- no session found for current thread异常
- Spring整合hibernate No Session found for current thread
- Spring3与hibernate4 整合 (No Session found for current thread)
- hibernate异常no session found for current thread
- Hibernate No Session found for current thread异常分析
- No Session found for current thread
- No Session found for current thread
- No Session found for current thread
- Hibernate4 No Session found for current thread
- No Session found for current thread
- getSessionFactory No Session found for current thread
- 【JAVA】No Session found for current thread
- 单元测试 : No Session found for current thread
- Exception:No Session found for current thread
- No Session found for current thread
- 关于Spring3.2+Hibernate4.1整合问题:No Session found for current thread
- SpringMVC 整合 hibernate 报错:No Session found for current thread
- 标签布局
- H
- 金明的预算方案DP(写伪了)
- 关于带图片的TextView-代码更改图片位置注意事项
- php curl选项列表(超详细)
- SSH整合开发之异常:No Session found for current thread
- Bootstrap(3)__Bootstrap基础<导航,轮播,下拉表>
- Linux 之间 scp免密传文件
- CSS 的预处理程序--------------------Sass、LESS、Stylus
- 深入理解jvm(五):java内存模型和线程
- 哈希算法实现图像相似度比较(Python&OpenCV)
- slf4j的介绍
- 数据库连接池c3p0配置c3p0-config.xml详解
- TimesIsMoney