向 A表和B表 插入数据 ,需要事务控制, A 表插入数据成功 ,B 插入数据不成功 (原因是故意出现插入到表的数据格式错误),查看数据库表 ,A 表的插入的数据还存在 ,事务并没有回滚,我的代码如下:
Service 接口类 :public String saveApp(@WebParam(name="sessionId") String sessionId,@WebParam(name="app") App app);Service 接口实现类public String saveApp(String sessionId,App app) throws TotalException {
try{
AppPojo appPojo=new AppPojo();
appPojo.setAppDesc(app.getAppDesc());
appPojo.setAppFee(app.getAppFee());
appPojo.setAppIcon("");
appPojo.setAppId(UUIDGenerator.getUUID());
appPojo.setAppName(app.getAppName());
appPojo.setAppNo(app.getAppNo());
appPojo.setAppType(app.getAppType());
VersionInfoPojo version=new VersionInfoPojo();
version.setPublishPath("");
version.setVersionId(UUIDGenerator.getUUID());
version.setAppId(appPojo.getAppId());
version.setPublishType("a");
dao.saveApp(appPojo);
dao.saveVersionInfo(version);

}catch(DataAccessException de){
System.out.println("service execute exception");
throw new TotalException("error");
}
return null;
}
TotalException  为自定义一个异常类 Dao  接口类 :public String saveApp(AppPojo apppojo);
public String saveVersionInfo(VersionInfoPojo version);
Dao 接口实现类  public String saveApp(AppPojo appPojo){
this.getSqlMapClientTemplate().insert("store.insertApp",appPojo);
//saveVersionInfo(appPojo.getVersionInfo());
return appPojo.getAppId();
}

public String saveVersionInfo(VersionInfoPojo version){
version.setVersionNo(StringUtil.dateToString("yyyyMMdd", new Date()));
version.setPublishTime(new Date());
this.getSqlMapClientTemplate().insert("store.insertVersion",version);
return null;
}
spring 配置文件 :<bean id="dataSource_apprsal"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="${jdbc.driverClassName}">
</property>
<property name="url" value="${jdbcapprsal.url}"></property>
<property name="username" value="${jdbcapprsal.username}"></property>
<property name="password" value="${jdbcapprsal.password}"></property>
<property name="maxActive" value="100"></property>
<property name="maxIdle" value="30"></property>
<property name="maxWait" value="1000"></property>
<property name="removeAbandoned" value="true"></property>
<property name="removeAbandonedTimeout" value="60"></property>
<property name="logAbandoned" value="true"></property>
</bean>
<!-- sql map client 配置 -->
 <bean id="sqlMapClient_apprsal"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation"
value="classpath:/ibatis-sql-map-config-easepal.xml" />
<property name="dataSource" ref="dataSource_apprsal" />
</bean>
<!-- ************************************************************************-->
<!-- //////////////////////ibatis事务代理配置///////////////////////////////-->
<!-- ************************************************************************-->

<!-- 配置哪些类哪些方法使用事务 -->
<bean id="transactionManager_Apprsal"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource_apprsal"></property>
</bean>
<tx:advice id="txAdvice_Apprsal"  transaction-manager="transactionManager_Apprsal">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"  rollback-for="TotalException" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="allDAO_Apprsal"
expression="execution(* com.easepal..service.impl.*SerivceImpl.*(..))" />
<aop:advisor advice-ref="txAdvice_Apprsal" pointcut-ref="allDAO_Apprsal" />
</aop:config>
         
        <bean id="daoAppStore" 
class="com.easepal.app.store.dao.impl.StoreDaoImpl">
<property name="sqlMapClient">
<ref bean="sqlMapClient_apprsal" />
</property>
</bean>
         <jaxws:endpoint xmlns:tns="http://easepal.com/app/store/"
id="StoreService" implementor="#Impl_StoreService"
endpointName="tns:StorePort" serviceName="tns:StoreService" 
address="/app/StoreService"/>
  <bean id="Impl_StoreService" class="com.easepal.app.store.service.impl.StoreServiceImpl">
<property name="dao" ref="daoAppStore"></property>
</bean>

解决方案 »

  1.   

    TotalException 你继承了哪个exception?
      

  2.   

    楼主要打自己屁屁,目前发现一个手写错误
     expression="execution(* com.easepal..service.impl.*SerivceImpl.*(..))" />
    <bean id="Impl_StoreService" class="com.easepal.app.store.service.impl.StoreServiceImpl">
    你仔细对比下就知道了.......SerivceImpl........................
      

  3.   

    ServiceImpl 写成  SerivceImpl   了
      

  4.   

    仔细看   expression="execution(* com.easepal..service.impl.*SerivceImpl.*(..))" />SerivceImpl是不是写错了 应该为ServiceImpl i和v的位置是不是写反了
      

  5.   

    另外建议lz 以后写路径的时候最好用copy方式,保险。 否则字母写错了很难发现的!