SSH dao层异常 org.hibernate.HibernateException: No Session found for current thread
解决方法:
在 接口方法中添加 事务注解 即可。
public interface IBase<PK extends Serializable, T> {@Transactionalvoid add(T t);@TransactionalUser get(PK id);@TransactionalList<T> list();@Transactionalvoid update(T t);// @Transactionalvoid delete(PK id); }
以下为异常原文信息:
org.hibernate.HibernateException: No Session found for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:941)
at com.ht.dao.impl.UserDaoImpl.getSession(UserDaoImpl.java:49)
at com.ht.dao.impl.UserDaoImpl.get(UserDaoImpl.java:27)
at com.ht.dao.impl.UserDaoImpl.delete(UserDaoImpl.java:43)
at com.ht.dao.impl.UserDaoImpl.delete(UserDaoImpl.java:1)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
at com.sun.proxy.$Proxy20.delete(Unknown Source)
at com.ht.service.impl.UserServiceImpl.delete(UserServiceImpl.java:35)
at com.ht.service.impl.UserServiceImpl.delete(UserServiceImpl.java:1)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
at com.sun.proxy.$Proxy22.delete(Unknown Source)
at com.ht.test.HibernateTest.delete(HibernateTest.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207)
@Transactional
转载于:https://www.cnblogs.com/bg7c/p/7923107.html
SSH dao层异常 org.hibernate.HibernateException: No Session found for current thread相关推荐
- org.hibernate.HibernateException: No Session found for current thread
spring.springmvc和hibernate整合 在sessionFactory.getCurrentSession()时,出现以下异常 No Session found for curren ...
- Redisson报异常attempt to unlock lock, not locked by current thread by node id解决方案
Redisson报异常attempt to unlock lock, not locked by current thread by node id解决方案 问题背景 解决方案 总结 Lyric: 那 ...
- 带分页功能的SSH整合,DAO层经典封装
任何一个封装讲究的是,使用,多状态. Action: 任何一个Action继承分页有关参数类PageManage,自然考虑的到分页效果,我们必须定义下几个分页的参数.并根据这个参数进行查值. 然后在继 ...
- 基于hibernate的泛型Dao层设计
泛型是JDK1.5的一个新的特性,使用泛型机制编写的程序代码要比那些杂乱的使用Object变量,然后再进行强制类型转换的代码具有更好的安全性和可读性.如果你的系统运行在JDK1.5以上的版本上,建议多 ...
- SSH中为什么action需要用多例而dao层和service层为什么就用单例就可以
很简单的道理,就跟你自来水一样,有很多的水龙头,但水管只有一个. 为啥要很多水龙头,因为有多个人同时用:为了避免长队,只能这样来分担压力 为啥只有一个水管,易维护,集中处理. 使用单例,是由于没必要每 ...
- php dao 接口,SSH中公共Dao层、Dao接口
早做项目时候!为了优化代码可以创建公共类与接口 先写一个Dao层的公共接口,在里面实现增删改查等各种功能 public interface IBaseDao { //增加 public void sa ...
- ssh整合:spring+springmvc+hibernate
1 创建maven的web项目 2 补全项目结构 3 补全web.xml <?xml version="1.0" encoding="UTF-8"?> ...
- java action dao_java中Action层、Service层和Dao层的功能区分
一.Action/Service/DAO简介: Action是管理业务(Service)调度和管理跳转的. Service是管理具体的功能的. Action只负责管理,而Service负责实施. DA ...
- [转]JAVA中Action层, Service层 ,modle层 和 Dao层的功能区分
首先这是现在最基本的分层方式,结合了SSH架构.modle层就是对应的数据库表的实体类.Dao层是使用了Hibernate连接数据库.操作数据库(增删改查).Service层:引用对应的Dao数据库操 ...
- java basedaoimpl_java web项目DAO层通用接口BaseDao与实现类BaseDaoImpl
在spring+hibernate的web项目中,处理数据层通常会使用Spring框架提供的HibernateTemplate类提供的方法.通常的用法是每一个实体类对应的去写DAO层的接口和实现类.每 ...
最新文章
- win10找不到局域网Linux,技术员解惑win10系统访问不了NAS和linux网络共享的详细办法...
- 时间选择控件在不同场景下的应用
- java 流程控制_Java流程控制
- kinect:0x80080014
- mysql5.6修改默认目录_MySQL修改默认存储路径
- [C++11]常量表达式函数
- 社会工程学***的八种常用方法
- Kali linux学习入门-安装Kali Linux 后需要做的 20 件事
- ArcEngine中加载ArcGIS Server地图服务
- 缓存 ASP.NET 页
- php记录上次观看记录,PHP Cookei记录用户历史浏览信息的代码
- C#利用委托跨线程更新UI数据
- javaSE---最大值最小值和冒泡排序及随机数的讲解
- GradientDrawable
- GNU nano介绍
- linux ps1 日期格式,Linux下bash的PS1
- 前5名:Raspberry Pi龙卷风警告系统,用于物联网开发的4个开放式开发板等
- 80x86 汇编语言,大写变小写,小写变大写,数字原样输出
- win7开启超级管理员账户(Administrator)
- 迅雷软件一直出现崩溃问题的解决方法
热门文章
- Windows Mobile Sensors API库的设计
- 三种新型DDoS反射攻击出现
- Mapreduce和Yarn概念,参数优化,作用,原理,MapReduce计数器 Counter,MapReduce 多job串联之ControlledJob(来自学习资料)...
- rac节点频繁重启的问题分析
- java_自由块(静态块和非静态块)
- [转载][翻译]Go的50坑:新Golang开发者要注意的陷阱、技巧和常见错误[1]
- lsb_release -a 查询Linux系统版本
- 【leetcode】sort list(python)
- 微软开放技术热烈祝贺开源社成立!
- 转:为 setuptools 开路搭桥