解决方法:

在 接口方法中添加 事务注解 即可。

public interface IBase<PK extends Serializable, T> {

    @Transactional
void add(T t); @Transactional
User get(PK id); @Transactional
List<T> list(); @Transactional
void update(T t); // @Transactional
void 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

SSH dao层异常 org.hibernate.HibernateException: No Session found for current thread的更多相关文章

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

    spring.springmvc和hibernate整合 在sessionFactory.getCurrentSession()时,出现以下异常 No Session found for curren ...

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

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

  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. hibernate在使用getCurrentSession时提示no session found for current thread

    大致错误片段 org.hibernate.HibernateException: No Session found for current thread at org.springframework. ...

  5. spring整合hibernate的时候报异常org.hibernate.HibernateException: createQuery is not valid without active transaction

    在整合Spring4+hibernate4时候,当代码执行到dao中CRUD操作时,报了一个异常, org.hibernate.HibernateException: createQuery is n ...

  6. SSH框架新线程下执行数据库持久化时 No Session found for current thread

    架构:SSH框架 问题:多线程下的持久化操作 异常No Session found for current thread出现环境: SSH框架,采用声明式事务, 通过sessionFactory.ge ...

  7. Hibernate: No Session found for current thread

    在Struts2+Hibernate+Srping项目中经常会遇到这种问题 我知道的一种情况是: Spring的事务配置中没有配置好异常出现处的路径 <aop:advisor pointcut= ...

  8. SSH整合方案一(带有hibernate.cfg.xml)

    整体结构 1.导入响应的jar包 2.在web.xml中配置struts的过滤器和spring整合web的监听器 <!--配置Spring整合web的监听器--> <listener ...

  9. SSH框架整合中Hibernate实现Dao层常用结构

    一.疑惑 一直以来,我在使用SSH框架的时候经常会发现后者有疑虑到底使用hibernate的那种方法或者如何配置hibernate来操作数据库,经过 一段时间的学习下面我来总结一下,常用的dao层配置 ...

随机推荐

  1. TreeListView排序不对

    winForm控件TreeListView按照一定顺序后添加项,后发觉排序顺序自己变了,解决办法: TreeListViewItem viewItem = new TreeListViewItem() ...

  2. physdiskwrite 的简单使用

    physdiskwrite 的简单使用 参考  https://m0n0.ch/wall/physdiskwrite.php 来源 https://www.cnblogs.com/EasonJim/p ...

  3. 多进程,多线程,使用sqlalchemy 创建引擎(单例模式),闭包装饰器承载数据库会话,装饰模型类的类方法

    python 多进程,多线程,使用 sqlalchemy 对数据库进行操作 创建引擎 & 获取数据库会话: 使用类的方式,然后在对象方法中去创建数据库引擎(使用单例,确保只创建一个对象,方法里 ...

  4. win10重装系统修改信息

    在安装win10系统之前要先进行ahci硬盘模式更改 ,以防止win10系统安装完成后出现蓝屏现象,那么如何进行ahci硬盘模式bios设置呢?今天我们就以映泰主板为大家介绍u盘装win10系统硬盘模 ...

  5. [LeetCode] 121. 买卖股票的最佳时机 ☆(动态规划)

    https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/solution/xiang-xi-tong-su-de-si-lu- ...

  6. laravel管理模型插入

    post控制器public function comment(Post $post,Request $request){ try{ if(empty($request->content)){ E ...

  7. python 元类理解

    原文来自:https://segmentfault.com/a/1190000011447445 学懂元类,你只需要知道两句话: 道生一,一生二,二生三,三生万物 我是谁?我从哪来里?我要到哪里去? ...

  8. Spring 的 @Primary 注解

    简单的说,就是当Spring容器扫描到某个接口的多个 bean 时,如果某个bean上加了@Primary 注解 ,则这个bean会被优先选用,如下面的例子: @Component public cl ...

  9. orm多表的创建和基于对象的查询

    创建模型 实例:我们来假定下面这些概念,字段和关系 作者模型:一个作者有姓名和年龄. 作者详细模型:把作者的详情放到详情表,包含生日,手机号,家庭住址等信息.作者详情模型和作者模型之间是一对一的关系( ...

  10. evpp return index.html

    https://github.com/yuqingtong1990/ggtalk_server/blob/99f0f85c683dc0a0c3e76dcae611f60f6456eed6/server ...