NutzCN Logo
问答 这段代码为什么没有回滚
发布于 2208天前 作者 tankHui 1367 次浏览 复制 上一个帖子 下一个帖子
标签:
Trans.exec((Atom) () -> {
                if(StringTool.isNotNull(ids)) {
                    String[] idss = ids.split(",");
                    for (String id : idss){
                        if (!StringUtil.isEmpty(id)){
                            ZbzyZbInfo info = super.fetch(ZbzyZbInfo.class, id);
                            ZbzyZbRentOut rent = super.fetch(ZbzyZbRentOut.class, info.getInfoId());
                            ZbzyZbVehicle vehicle = super.fetch(ZbzyZbVehicle.class, rent.getToolId());
                            super.delete(info);
                            super.delete(rent);
                            super.delete(vehicle);
                        }
                    }

                }
            });
9 回复

之前我把super.delete(info);这句话放到了ZbzyZbInfo info = super.fetch(ZbzyZbInfo.class, id);这句话后面,然后ZbzyZbRentOut rent = super.fetch(ZbzyZbRentOut.class, info.getInfoId());这句话报空指针异常但是info这条数据已经删除了

是不是有更高层的事务模板, 把这一层的事务忽略了

```
public boolean deleteInfo(String ids){
boolean result = false;
try{
Trans.exec((Atom) () -> {
if(StringTool.isNotNull(ids)) {
String[] idss = ids.split(",");
for (String id : idss){
if (!StringUtil.isEmpty(id)){
ZbzyZbInfo info = super.fetch(ZbzyZbInfo.class, id);
ZbzyZbRentOut rent = super.fetch(ZbzyZbRentOut.class, info.getInfoId());
ZbzyZbVehicle vehicle = super.fetch(ZbzyZbVehicle.class, rent.getToolId());
super.delete(info);
super.delete(rent);
super.delete(vehicle);
}
}

            }
        });
        result = true;
    } catch (Exception ex){
        log.error("AdminZbRentOutVehicleInfoService:insertInfo", ex);
    }
    return result;
}

大佬 这个是完整的方法

异常信息贴来看看

java.lang.NullPointerException
	at com.zbzy.services.backend.zbzy.AdminZbRentOutVehicleInfoService.lambda$deleteInfo$2(AdminZbRentOutVehicleInfoService.java:88)
	at org.nutz.trans.Trans.exec(Trans.java:174)
	at org.nutz.trans.Trans.exec(Trans.java:132)
	at com.zbzy.services.backend.zbzy.AdminZbRentOutVehicleInfoService.deleteInfo(AdminZbRentOutVehicleInfoService.java:80)
	at com.zbzy.services.backend.zbzy.AdminZbRentOutVehicleInfoService$$NUTZAOP._aop_invoke(AdminZbRentOutVehicleInfoService.java:3)
	at org.nutz.aop.InterceptorChain.invoke(InterceptorChain.java:77)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:57)
	at org.nutz.aop.interceptor.TransactionInterceptor.filter(TransactionInterceptor.java:34)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
	at com.zbzy.services.backend.zbzy.AdminZbRentOutVehicleInfoService$$NUTZAOP.deleteInfo(AdminZbRentOutVehicleInfoService.java:1)
	at com.zbzy.web.backend.module.admin.zbzy.AdminZbRentOutVehicleInfoModule.delete(AdminZbRentOutVehicleInfoModule.java:148)
	at com.zbzy.web.backend.module.admin.zbzy.AdminZbRentOutVehicleInfoModule$$NUTZAOP._aop_invoke(AdminZbRentOutVehicleInfoModule.java:2)
	at org.nutz.aop.InterceptorChain.invoke(InterceptorChain.java:77)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:57)
	at com.zbzy.common.oplog.interceptor.CommonInterceptor.filter(CommonInterceptor.java:49)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
	at com.zbzy.web.backend.module.admin.zbzy.AdminZbRentOutVehicleInfoModule$$NUTZAOP.delete(AdminZbRentOutVehicleInfoModule.java:1)
	at com.zbzy.web.backend.module.admin.zbzy.AdminZbRentOutVehicleInfoModule$FM$delete$35c5616d379adc29dbf72ede5743ba9c.invoke(AdminZbRentOutVehicleInfoModule.java)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:38)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2527)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2516)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
log4j: 2018-10-30 16:23:32,720 [http-apr-8080-exec-2] DEBUG org.nutz.ioc.impl.NutIoc - Get 'oplog'<interface com.zbzy.common.oplog.interceptor.Oplog>
log4j: 2018-10-30 16:23:32,720 [http-apr-8080-exec-2] DEBUG org.nutz.ioc.impl.NutIoc - 	 >> Load definition name=oplog
log4j: 2018-10-30 16:23:32,720 [http-apr-8080-exec-2] DEBUG org.nutz.ioc.loader.combo.ComboIocLoader - Found IocObject(oplog) in JsonLoader(paths=[ioc/])
log4j: 2018-10-30 16:23:32,720 [http-apr-8080-exec-2] DEBUG org.nutz.ioc.impl.NutIoc - 	 >> Make...'oplog'<interface com.zbzy.common.oplog.interceptor.Oplog>
log4j: 2018-10-30 16:23:32,720 [http-apr-8080-exec-2] DEBUG org.nutz.ioc.impl.ScopeContext - Save object 'oplog' to [app] 
log4j: 2018-10-30 16:23:32,721 [http-apr-8080-exec-2] DEBUG org.nutz.ioc.impl.ScopeContext - Remove object 'oplog' from [app] 

是不是有aop 事务

来自炫酷的 NutzCN

$aop : {
		type : 'org.nutz.ioc.aop.config.impl.JsonAopConfigration',
		fields : {
			itemList : [ 
			             [ 'com.zbzy.services\\..*', '(insert|update|delete|tx).*', 'ioc:txREPEATABLE_READ' ]
			             [ 'com.zbzy.web.backend.module\\..*', '.*', 'ioc:common' ]
						]
		}
	}

因为在aop事务作用域内,所以不回滚

你可以看看NutTxDao,开启独立事务

来自炫酷的 NutzCN

添加回复
请先登陆
回到顶部