项目中使用到了hibernate以及spring事务控制,在service层增加事务控制但是遇到异常没有回滚。
代码如下:
配置文件
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
default-autowire="byName" default-lazy-init="true">
<!-- 字典信息 -->
com.cvicse.tech.dic.model.DCoreParam
com.cvicse.tech.dic.model.DDicContent
com.cvicse.tech.dic.model.DDicType
com.cvicse.tech.dic.model.DZoneCode
com.cvicse.tech.dic.model.DDepMode
<!-- see /components/orm/hibernate/meta/dialect.properties for all Dialect -->
${hibernate.dialect}
${hibernate.show_sql}
${hibernate.cache.provider_class}
${hibernate.cache.use_query_cache}
id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
service层代码
@Transactional
public class LrbManager {
private LrbDAOImpl lrbDao;
private Sql sql;
@Transactional
public void delete() throws ApplicationException {
sql.setSql("insert into sjcj_lrb
(SXH
, XM
, HC
, SNTQLJ
, BYS
, BNLJS
, JBJG
, JBR
, JBSJ
, DWMC
, SSRQ
) values('5','1','1','121','1','1','1','1','2014-03-30','1','2014-03-30')");
sql.executeUpdate();
sql.setSql("insert into sjcj_lrb
(SXH
, XM
, HC
, SNTQLJ
, BYS
, BNLJS
, JBJG
, JBR
, JBSJ
, DWMC
, SSRQ
) values('6','1','1','121','1','1','1','1','2014-03-30','1','2014-03-30')");
sql.executeUpdate();
//抛异常语句
sql.setSql("delte from sjcj_lrb1 ");
sql.executeUpdate();
}
}
/**
*关于SQL语句的一些操作
*/
public class Sql extends JdbcDaoSupport {