MyException - 我的异常网
当前位置:我的异常网» J2EE » spring与hibernate整合,当手动抛出runtimeExceptio

spring与hibernate整合,当手动抛出runtimeException时,spring无论怎么都不能让事务回滚,请前辈指教(2)

www.MyException.Cn  网友分享于:2013-02-20  浏览:176次

//ctx.destroy();
}
}

配置文件applicationContext.xml
<?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:tx="http://www.springframework.org/schema/tx"



xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-2.5.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
>

<context:annotation-config></context:annotation-config>
<context:component-scan base-package="spring"></context:component-scan>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  <property name="url" value="jdbc:mysql://localhost:3306/webdb"/>
  <property name="username" value="root"/>
  <property name="password" value="19830112"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  <property name="dataSource" ref="dataSource" />
  <property name="annotatedClasses">
  <list>
    <value>spring.entity.User</value>
    <value>spring.entity.Log</value>
  </list>
  </property>
  <property name="hibernateProperties">
    <props>
     <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
     <prop key="hibernate.show_sql">true</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"/>
</beans> 

------解决方案--------------------
挖个老坟,刚刚遇到同样的问题
解决方法:使用MySQL数据库时,表必须为InnoDB类型

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有