spring配置文件:
第一个xml
<context:annotation-config/>
<aop:config proxy-target-class="true"></aop:config>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
<property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:orcl" />
<property name="user" value="ierp" />
<property name="password" value="ierp" />
<property name="initialPoolSize" value="10" />
<property name="maxPoolSize" value="15" />
<property name="minPoolSize" value="5" />
<property name="maxIdleTime" value="1000" />
</bean>
<!-- 设置JDBC信息 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
<aop:config proxy-target-class="true"></aop:config>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
第二个xml
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="poBaseService" class="bin._08purchase._0801purchaseorder._080101pobase.POBaseImpl"/>
<bean id="actionpobaselist" class="bin._08purchase._0801purchaseorder._080101pobase.ActionPOBaseList"/>
<bean id="actionpobasemanager" class="bin._08purchase._0801purchaseorder._080101pobase.ActionPOBaseManager"/>
<bean id="actionpobasesingleinfo" class="bin._08purchase._0801purchaseorder._080101pobase.ActionPOBaseSingleInfo"/>
@Transactional(propagation=Propagation.REQUIRED,rollbackFor=java.sql.SQLException.class)
public ExecMsg e_updatePoBase(POBaseBean poBaseBean) {
ExecMsg execMsg = new ExecMsg(); // 返回参数
try {
// 设置执行主键
execMsg.setContent(poBaseBean.getPocode());
// 构建sql语句
StringBuffer sql = new StringBuffer(); // sql代码
sql.append(" update tb_pobase set COCODE = ? ,CPCODE = ? ,POAD = to_date(?,'yyyy-mm-dd') ,POADVANCE = ? ");
sql.append(" ,POAPCODE = ? ,POAPRO = ? ,POBCODE = ? ,POCODE = ? ,PODATE = to_date(?,'yyyy-mm-dd') ,PODESC = ? ");
sql.append(" ,POISTAX = ? ,POREMARK = ? ,POSTATUS = ? ,POTAX = ? ,POTTYPE = ? ,POTYPE = ? where POCODE= ? ");
Object[] params = new Object[] { poBaseBean.getCocode(),
poBaseBean.getCpcode(), poBaseBean.getPoad(),
poBaseBean.getPoadvance(), poBaseBean.getPoapcode(),
poBaseBean.getPoapro(), poBaseBean.getPobcode(),
poBaseBean.getPocode(), poBaseBean.getPodate(),
poBaseBean.getPodesc(), poBaseBean.getPoistax(),
poBaseBean.getPoremark(), poBaseBean.getPostatus(),
poBaseBean.getPotax(), poBaseBean.getPottype(),
poBaseBean.getPotype(), poBaseBean.getPocode() }; // sql参数
// 执行数据库更新
//int updatecount = JdbcExecute.execUpdate(jdbcTemplate, sql, params);
int updatecount =jdbcTemplate.update(sql.toString(),params);
//这是错误的数据库操作,用来测试事务的。但是从来没成功过。
//当这个产生问题时,上一个仍然在执行。
Object[] paramstest = new Object[] { 1, "zhangshan" };
StringBuffer sqltest = new StringBuffer(
" insert into tb_test2 (tcode,tname) values (?,?)");
jdbcTemplate.update(sqltest.toString(),paramstest);
execMsg.setStatus(1);
execMsg.setMsg("更新编号为" + poBaseBean.getPocode() + "的记录成功,更新数据"
+ updatecount + "条。");
} catch (Exception e) {
execMsg.setStatus(0);
execMsg.setMsg("更新编号为" + poBaseBean.getPocode() + "的记录错误,原因:"
+ e.getMessage());
ExceptionUtil.LogException(this.getClass().getName(), jdbcTemplate,
e);
}
return execMsg;
}
一直不能保证事务的完整性,所以很困惑。
------解决方案--------------------
readonly = "false"
------解决方案--------------------
readOnly = false