架个spring4+hibernate4的demo,dao层直接注入的sessionFactory,然后用getCurrentSession方法获取session,然后问题来了,直接报错: Could not obtain transaction-synchronized Session for current thread 提示无法获取当前线程的事务同步session,略微奇怪,这和事务有什么关系..然后百度一下有人说改成用openSession方法就好了,那我又百度了一下这2个方法的区别:…
在开发中,碰到到了Could not obtain transaction-synchronized Session for current thread异常,因此特意记录下. 一.问题的产生 在使用Hibernate时碰到了如下异常: 检查了代码发现是代码中用sessionFactory.getCurrentSession()这样获取session,导致抛了这异常. 二.问题的解决过程 (1)先看下Hibernate相关的配置 H…
Could not obtain transaction-synchronized Session for current thread 这个异常之前非常让我头大.对于网上的各种说法都试了一下反正都不行.现在终于使这个异常消失了,但是现在(2017-7-8)还搞不清真正的原因. 这是异常的一部分. org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thre…
spring与hibernate整合报错 org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:134) org.hibernate.internal.S…
场景:把从客户端提交的任务放到线程池执行 异常:HibernateException: Could not obtain transaction-synchronized Session for current thread 猜测: 根据关键词猜测可能的原因: transaction.synchronized.session.current thread 由于这个操作是在Service中做的,又提到了事物.会话.当前线程,所以定位代码,发现是执行ADD操作报错 这块代码之前没有问题,在加了…