我想再问下 ,再service层下调用 两个dao层的数据插入的方法 ,现在我测试事务回滚 ,第一个dao 层插入数据库成功的 ,第二个插入数据库是不成功的 ,为什么事务没有回滚?
这个业务逻辑层的代码 Java code
public String saveParam(EuserComm euserComm, Bp[] bp, Temp[] temps, Bo[] bo) {
if(bp==null||bp.length==0){
throw new RuntimeException("RC002");
}
BpPojo[] bpList=new BpPojo[bp.length];
for(int i=0;i<bp.length;i++){
BpPojo bpPojo=new BpPojo();
Bp bpObj=bp[i];
bpPojo.setBpId(UUIDGenerator.getUUID());
bpPojo.setRegisterId(bpObj.getRegisterId());
bpPojo.setUserName(userDao.getUserNameByRegId(bpObj.getRegisterId()));
bpPojo.setMeasureTime(StringUtil.dateFormat("yyyyMMddHHmm", bpObj.getMeasureTime()));
bpPojo.setProductNo(euserComm.getProductNo());
bpPojo.setSendTime(StringUtil.dateFormat("yyyyMMddHHmm", euserComm.getSendTime()));
bpPojo.setSp(bpObj.getSp());
bpPojo.setDp(bpObj.getDp());
int pp=bp[i].getSp()-bp[i].getDp();
bpPojo.setPp(pp);
bpList[i]=bpPojo;
}
bpDao.saveBp(bpList);
if(temps==null||temps.length==0){
throw new RuntimeException("RC002");
}
TempPojo[] tempList=new TempPojo[temps.length];
String userName=userDao.getUserNameByRegId(temps[0].getRegisterId());
for(int i=0;i<temps.length;i++){
TempPojo tempPojo=new TempPojo();
Temp temp=temps[i];
tempPojo.setTempId(UUIDGenerator.getUUID());
tempPojo.setRegisterId(temp.getRegisterId());
tempPojo.setProductNo(euserComm.getProductNo());
tempPojo.setSendTime(StringUtil.dateFormat("yyyyMMddHHmm",euserComm.getSendTime()));
tempPojo.setUserName(userName);
tempPojo.setMeasureTime(StringUtil.dateFormat("yyyyMMddHHmm",temp.getMeasureTime()));
tempPojo.setTempValue(Float.parseFloat(temp.getTempValue()));
tempList[i]=tempPojo;
}
tempDao.saveTemp(tempList);
return "RC001";
}
[/code]
这个业务逻辑层的代码 Java code
public String saveParam(EuserComm euserComm, Bp[] bp, Temp[] temps, Bo[] bo) {
if(bp==null||bp.length==0){
throw new RuntimeException("RC002");
}
BpPojo[] bpList=new BpPojo[bp.length];
for(int i=0;i<bp.length;i++){
BpPojo bpPojo=new BpPojo();
Bp bpObj=bp[i];
bpPojo.setBpId(UUIDGenerator.getUUID());
bpPojo.setRegisterId(bpObj.getRegisterId());
bpPojo.setUserName(userDao.getUserNameByRegId(bpObj.getRegisterId()));
bpPojo.setMeasureTime(StringUtil.dateFormat("yyyyMMddHHmm", bpObj.getMeasureTime()));
bpPojo.setProductNo(euserComm.getProductNo());
bpPojo.setSendTime(StringUtil.dateFormat("yyyyMMddHHmm", euserComm.getSendTime()));
bpPojo.setSp(bpObj.getSp());
bpPojo.setDp(bpObj.getDp());
int pp=bp[i].getSp()-bp[i].getDp();
bpPojo.setPp(pp);
bpList[i]=bpPojo;
}
bpDao.saveBp(bpList);
if(temps==null||temps.length==0){
throw new RuntimeException("RC002");
}
TempPojo[] tempList=new TempPojo[temps.length];
String userName=userDao.getUserNameByRegId(temps[0].getRegisterId());
for(int i=0;i<temps.length;i++){
TempPojo tempPojo=new TempPojo();
Temp temp=temps[i];
tempPojo.setTempId(UUIDGenerator.getUUID());
tempPojo.setRegisterId(temp.getRegisterId());
tempPojo.setProductNo(euserComm.getProductNo());
tempPojo.setSendTime(StringUtil.dateFormat("yyyyMMddHHmm",euserComm.getSendTime()));
tempPojo.setUserName(userName);
tempPojo.setMeasureTime(StringUtil.dateFormat("yyyyMMddHHmm",temp.getMeasureTime()));
tempPojo.setTempValue(Float.parseFloat(temp.getTempValue()));
tempList[i]=tempPojo;
}
tempDao.saveTemp(tempList);
return "RC001";
}
[/code]
解决方案 »
- 刚刚搭建了个SSH2框架整合,但出来点问题...请各位高手给解决一下!!
- 求经验!
- java中在linux下读windows文件
- weblogic 小问题
- 高手请看非常具有挑战性的算法(希望各位高手给出JAVA编写的怪物(V)的逃脱算法)
- [求助]JSP的突法奇想~
- HQL 的问题
- 请问weblogic也有像websphere一样的集成开发环境吗?
- 如何在WEBLOGIC 中设置与weblogic同时启动的类?
- 请问怎样在client里得到一个Sessionbean 的 home接口,谢谢!
- 急求!!java swing中点击按钮弹出日历对话框,可选择日期显示在文本框中,文本框和按钮在jpanel中
- Spring环境下怎么把一个变量放在ServletContext里
后来通过Spring的AOP切入解决
<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="login" propagation="REQUIRED" />
<tx:method name="signOut" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" rollback-for="Throwable"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="copy*" propagation="REQUIRED"/>
<tx:method name="getSerial" propagation="REQUIRED"/>
<!-- tx:method name="*" read-only="true" /-->
</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>
怎么还有手动回滚 ,若有手动回滚 ,又是怎样写的
你自己用JDBC写个简单的事务型操作吧,MYSQL数据库默认就好像不支持事务操作,如果你解决了问题麻烦发下方案俺也学习下
public String saveParam(EuserComm euserComm, Bp[] bp, Temp[] temps, Bo[] bo) {
try{if(bp==null||bp.length==0){
throw new RuntimeException("RC002");
}
BpPojo[] bpList=new BpPojo[bp.length];
for(int i=0;i<bp.length;i++){
BpPojo bpPojo=new BpPojo();
Bp bpObj=bp[i];
bpPojo.setBpId(UUIDGenerator.getUUID());
bpPojo.setRegisterId(bpObj.getRegisterId());
bpPojo.setUserName(userDao.getUserNameByRegId(bpObj.getRegisterId()));
bpPojo.setMeasureTime(StringUtil.dateFormat("yyyyMMddHHmm", bpObj.getMeasureTime()));
bpPojo.setProductNo(euserComm.getProductNo());
bpPojo.setSendTime(StringUtil.dateFormat("yyyyMMddHHmm", euserComm.getSendTime()));
bpPojo.setSp(bpObj.getSp());
bpPojo.setDp(bpObj.getDp());
int pp=bp[i].getSp()-bp[i].getDp();
bpPojo.setPp(pp);
bpList[i]=bpPojo;
}
bpDao.saveBp(bpList);
if(temps==null||temps.length==0){
throw new RuntimeException("RC002");
}
TempPojo[] tempList=new TempPojo[temps.length];
String userName=userDao.getUserNameByRegId(temps[0].getRegisterId());
for(int i=0;i<temps.length;i++){
TempPojo tempPojo=new TempPojo();
Temp temp=temps[i];
tempPojo.setTempId(UUIDGenerator.getUUID());
tempPojo.setRegisterId(temp.getRegisterId());
tempPojo.setProductNo(euserComm.getProductNo());
tempPojo.setSendTime(StringUtil.dateFormat("yyyyMMddHHmm",euserComm.getSendTime()));
tempPojo.setUserName(userName);
tempPojo.setMeasureTime(StringUtil.dateFormat("yyyyMMddHHmm",temp.getMeasureTime()));
tempPojo.setTempValue(Float.parseFloat(temp.getTempValue()));
tempList[i]=tempPojo;
}
tempDao.saveTemp(tempList);
return "RC001";
}
} catch(Exception e){
........
}
<tx:method name="save*" propagation="REQUIRED" rollback-for="Exception"/>
还是不行的话,看下面这个表达式错了没 <aop:pointcut id="allDAO_Apprsal"
expression="execution(* com.easepal..service.impl.*SerivceImpl.*(..))" />