我在spring3.0整合hibernate3.3 老是报异常 说是save is not valid without active transacton其中在UserService类里面 加入事物的方法如下: @Transactional(propagation=Propagation.REQUIRED)
public void save()
{
this.userDAO.saveUser();
this.logDAO.saveLog();
}在测试的时候 拿到的又是一个代理类 但是没有在方法上加事物 报异常说save is not valid without active transacton
这个问题有的人遇到了 有的人确能正常运行 难道和spring合hibernate的版本有关吗
public void save()
{
this.userDAO.saveUser();
this.logDAO.saveLog();
}在测试的时候 拿到的又是一个代理类 但是没有在方法上加事物 报异常说save is not valid without active transacton
这个问题有的人遇到了 有的人确能正常运行 难道和spring合hibernate的版本有关吗
解决方案 »
- 急求基于struts的新闻发布系统
- 启动tomcat时为什么回报java.lang.NoClassDefFoundError: javax/faces/FacesException呢?
- 谁知道在mysql中在使用函数的列可以对此列进行分组吗?
- 关于用lucene做高级搜索的问题
- struts+spring时,关于singleton使用的讨论
- hbm.xml文件里class的lazy属性我没设,默认应该是立即加载,为什么我默认是延迟加载呢?请问大虾
- 谁能跟我说说jfreechart生成的各个图的具体应用场合,50分不够可以再加啊
- 求救,关于上机管理系统的需求分析
- 向数据库中插入大量的纪录,应该怎么做?
- 在eclipse中配置了一个基础struts的test测试action,但是启动访问不了页面
- 用j2ee如何写出网页版的聊天室?
- thinking in java 中一条语句的疑惑?
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory" />
</bean>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
">
<!-- <bean name="us" class="com.bean.UserService"></bean> <property
name="userDAO"> <ref bean="ud"/> </property> </bean>
--> <bean id="user" class="com.bean.UserDAOAsepect"></bean>
<context:annotation-config />
<context:component-scan base-package="com.bean"></context:component-scan>
<!--
<aop:config> <aop:pointcut id="userPointcut"
expression="execution(public void com.bean.UserDAOImpl11.saveUser())"
/> <aop:aspect id="userAspect" ref="user"> <aop:before method="before"
pointcut-ref="userPointcut" /> <aop:after method="after"
pointcut="execution(public * com.bean..*.saveUser(..))" />
</aop:aspect> </aop:config>
--> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://127.0.0.1:3306/hibernate</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>123456</value>
</property>
<!--
<property name="initialSize"> <value>3</value> </property> <property
name="maxActive"> <value>100</value> </property> <property
name="maxIdle"> <value>5</value> </property> <property
name="maxWait"> <value>10</value> </property>
-->
</bean> <bean name="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.bean.User</value>
<value>com.bean.UserLog</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />
<!--
<aop:config> <aop:pointcut id="businessPointcut"
expression="execution(public * com.bean..*.save(..))" /> <aop:advisor
advice-ref="txAdvice" pointcut-ref="businessPointcut" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method
name="save" /> </tx:attributes> </tx:advice>
-->
</beans>
<property name="current_session_context_class">thread</property>
去掉<property name="current_session_context_class">thread</property>
类中就不能通过sessionfaction.getCurrentSession()获得session,而sessionfaction.OpenSession()又是打开新的session,当一个事物要管理多个方法时,比如异常回滚的问题,怎么解决???
我是菜鸟学习中同样出了这个错误???save is not valid without active transacton
是通过同一个connection 的,只有从当前线程中查找。所以不用配置这项。