Exception in thread "main" org.hibernate.HibernateException: save is not valid without active transaction
在spring4+hibernate4整合过程中,使用@Transactional注解事务会报"Exception in thread "main" org.hibernate.HibernateException: save is not valid without active transaction"错误,具体错误如下:
Exception in thread "main" org.hibernate.HibernateException: save is not valid without active transaction
at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:352)
at $Proxy18.save(Unknown Source)
at com.zainagou.dao.UserDaoImpl.addUser(UserDaoImpl.java:23)
at com.zainagou.dao.UserDaoImpl$$FastClassBySpringCGLIB$$98e1b102.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
at com.zainagou.dao.UserDaoImpl$$EnhancerBySpringCGLIB$$ac7c23a8.addUser(<generated>)
at com.zainagou.dao.MyTest.main(MyTest.java:19)
,后来发现是由于使用了如下配置导致上述问题:
<!-- session绑定当前线程 -->
<prop key="hibernate.current_session_context_class">thread</prop>
改配置在单独使用hibernate时进行当前线程绑定,在spring+hiberante整合中不需要这句配置,
spring提供了一个SpringSessionContext这个类来帮你获得和管理session
Exception in thread "main" org.hibernate.HibernateException: save is not valid without active transaction的更多相关文章
- org.hibernate.HibernateException: getFlushMode is not valid without active transaction
Spring & Hibernate 整合异常记录: org.hibernate.HibernateException: getFlushMode is not valid without a ...
- spring整合hibernate的时候报异常org.hibernate.HibernateException: createQuery is not valid without active transaction
在整合Spring4+hibernate4时候,当代码执行到dao中CRUD操作时,报了一个异常, org.hibernate.HibernateException: createQuery is n ...
- 异常:getHibernateFlushMode is not valid without active transaction; nested exception is org.hibernate.HibernateException: getHibernateFlushMode is not valid without active transaction getHibernateFlu
场景: 在使用spring整合hibernate调用的HibernateTemplate时报错解决: 在spring配置文件中添加事务的配置 <bean id="hibernateTr ...
- Exceprtion:e createQuery is not valid without active transaction; nested exception is org.hibernate.HibernateException: createQuery is not valid without active transaction
如果增加配置了current_session_context_class属性,查询的时候需要session.beginTrasaction()来开启事务
- Hibernate 与Spring整合出现 hibernate.HibernateException: createCriteria is not valid without active transaction
当 Hibernate 和 Spring 整合时,在 Spring 中指定的 Hibernate.cfg.xml 文件内容中要注释掉以下内容: <!-- Enable Hibernate's a ...
- save is not valid without active transaction
org.hibernate.HibernateException: save is not valid without active transaction at org.hibernate.cont ...
- Exception in thread "main" org.hibernate.TransientObjectException: object references an unsaved tran
今天在使用一对多,多对一保存数据的时候出现了这个错误 Hibernate错误: Exception in thread "main" org.hibernate.Transient ...
- ERROR: Field 'PostId' doesn't have a default value Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute statement
例子: Post p = new Post(); p.setPostId(3); p.setPostName("技术"); 在执行数据保持时提示session.save(p); 的 ...
- 在运行Hibernate Hello World程序的时候,抛如下错误: view plain Exception in thread "main" org.hibernate.exception.LockAcquisitionException 解决方法
在运行Hibernate Hello World程序的时候,抛如下错误: Exception in thread "main" org.hibernate.exception.Lo ...
随机推荐
- Spring ---annotation (重点)--AutoWired 不常用
1. 默认按类型 by type, 如果想用byname, 使用@Qualifier 2. 如果写在set上, @qualifier需要写在参数上 bean.xml: 默认bytype去找set方法, ...
- TcpView 查看端口的小工具(推荐)
介绍: TCPView是一个Windows程序,将显示你的详细清单的所有TCP和UDP端点在您的系统,包括拥有进程名称,远程地址和状态的TCP连接. 打开下面的链接就可以下载了. https://te ...
- Zookeeper的基本概念
Reference: http://mp.weixin.qq.com/s?src=3×tamp=1477979201&ver=1&signature=bBZqNrN ...
- sql语句:if exists语句使用
') begin print('exists ') end else begin print('no exists ') end go
- jquery textarea输入字符字数提示
效果: html代码: <textarea id="assayInfo" name="assayInfo" rows="3" cols ...
- Variation of e.touches, e.targetTouches and e.changedTouches
We have the following lists: touches: A list of information for every finger currently touching the ...
- 2.8. 创建 NSManagedObject 的子类 (Core Data 应用程序实践指南)
现在根据模型来创建NSManagedObject的子类.如果模型改变了,那就就重新生成这些文件.所以,不要在生成的文件里自定义方法,因为重新生成之后,这些修改就丢失了.假如确实需要重新生成自定义的方法 ...
- jQuery插件Flot实战Demo
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- 我用Cocos2d-x模拟《Love Live!学院偶像祭》的Live场景(五)
[前言和思路整理] 千呼万唤Shǐ出来!终于到最后一章啦~ 很抱歉这一章卡了那么久才发布.主要原因是家里电脑主板的内存插槽炸了,返厂后这周才收到,平时在公司也基本没什么时间写……再次表示歉意. 上一章 ...
- iOS 登陆之界面设置
1.界面构成 1.1. 效果图 1.2. 元素 背景图 用户名的输入框 密码的输入框 登陆按钮 忘记密码 用户注册 第三方登陆 两个分割线