Seata NullPointerException

起因

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
17:29:59.697 [Gateway.89c2f32d] [DubboServerHandler-172.17.0.1:20881-thread-199] INFO 
com.mysd.common.dubbo.filter.DubboProviderFilter -
DubboProvider Start(insertByPurOrder)
17:29:59.704 [Gateway.89c2f32d] [DubboServerHandler-172.17.0.1:20881-thread-199] INFO
com.mysd.common.MysdApplication -
QueryCount(1) SqlTime(1) SqlStr(SELECT a.scaling_factor , a.purchase_price , b.material_name, b.material_specification, a.barcode , a.auxiliary_unit, b.is_need_sncode FROM pub_material_detail_71 a left join pub_material_71 b on a.material_id = b.material_id WHERE a.md_id = /*mdId*/34 AND a.material_id = /*materialId*/23 AND a.group_id = /*groupId*/71 AND a.platform_id =/*platformId*/71)
17:29:59.712 [Gateway.89c2f32d] [DubboServerHandler-172.17.0.1:20881-thread-199] INFO
com.mysd.common.MysdApplication -
SqlResult(1) SqlTime(6) SqlStr(INSERT INTO rep_order_material_71 ( order_num, material_id, md_id, material_warehouse, auxiliary_quantity, scattered_quantity, material_quantity, unit_price, discount_price, total_amount, gift_flag, order_type, platform_id, group_id, create_by, material_name, material_specification, auxiliary_unit, create_time ) VALUES ( /*orderNum*/'37', /*materialId*/23, /*mdId*/34, /*materialWarehouse*/1, /*auxiliaryQuantity*/200, /*scatteredQuantity*/0, /*materialQuantity*/1200, /*unitPrice*/1000, /*discountPrice*/1000, /*totalAmount*/200000.00, /*giftFlag*/'0', /*orderType*/'201', /*platformId*/71, /*groupId*/71, /*createBy*/'admin', /*materialName*/'魔鬼梅洛红葡萄酒', /*materialSpecification*/'500ml', /*auxiliaryUnit*/'件', sysdate() ))
17:29:59.714 [Gateway.89c2f32d] [DubboServerHandler-172.17.0.1:20881-thread-199] ERROR
com.mysd.common.dubbo.filter.DubboExceptionFilter -
Dubbo 出现错误!
org.springframework.jdbc.UncategorizedSQLException:
### Error updating database. Cause: java.sql.SQLException: java.lang.NullPointerException
### The error may involve com.mysd.stock.storage.mapper.RepOrderMaterialMapper.insertOrderMaterial-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO rep_order_material_71 ( order_num, material_id, md_id, material_warehouse, auxiliary_quantity, scattered_quantity, material_quantity, unit_price, discount_price, total_amount, gift_flag, order_type, platform_id, group_id, create_by, material_name, material_specification, auxiliary_unit, create_time ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate() )
### Cause: java.sql.SQLException: java.lang.NullPointerException
; uncategorized SQLException; SQL state [null]; error code [0]; java.lang.NullPointerException; nested exception is java.sql.SQLException: java.lang.NullPointerException
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy171.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy184.insertOrderMaterial(Unknown Source)
at com.mysd.stock.storage.service.RepOrderMaterialServiceImpl.insertOrderMaterialList(RepOrderMaterialServiceImpl.java:1947)
at com.mysd.stock.storage.service.RepOrderMaterialServiceImpl.insertByPurOrder(RepOrderMaterialServiceImpl.java:951)
at com.mysd.stock.storage.service.RepOrderMaterialServiceImpl$$FastClassBySpringCGLIB$$66cf9a15.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)
at com.mysd.stock.storage.aspect.ToeknAspect.around(ToeknAspect.java:39)
at jdk.internal.reflect.GeneratedMethodAccessor404.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
at com.mysd.stock.storage.service.RepOrderMaterialServiceImpl$$EnhancerBySpringCGLIB$$c50246e6.insertByPurOrder(<generated>)
at org.apache.dubbo.common.bytecode.Wrapper13.invokeMethod(Wrapper13.java)
at org.apache.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:47)
at org.apache.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:84)
at org.apache.dubbo.config.invoker.DelegateProviderMetaDataInvoker.invoke(DelegateProviderMetaDataInvoker.java:56)
at org.apache.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:56)
at com.alibaba.dubbo.rpc.Invoker$CompatibleInvoker.invoke(Invoker.java:55)
at io.seata.integration.dubbo.alibaba.AlibabaDubboTransactionPropagationFilter.invoke(AlibabaDubboTransactionPropagationFilter.java:45)
at com.alibaba.dubbo.rpc.Filter.invoke(Filter.java:29)
at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83)
at io.seata.integration.dubbo.ApacheDubboTransactionPropagationFilter.invoke(ApacheDubboTransactionPropagationFilter.java:69)
at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83)
at com.mysd.common.dubbo.filter.DubboExceptionFilter.invoke(e:44)
at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83)
at org.apache.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:89)
at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83)
at org.apache.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:46)
at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83)
at org.apache.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:77)
at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83)
at com.mysd.common.dubbo.filter.DubboProviderFilter.invoke(g:145)
at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83)
at org.apache.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:129)
at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83)
at org.apache.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:152)
at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83)
at org.apache.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)
at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83)
at org.apache.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:41)
at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83)
at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:145)
at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:100)
at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:175)
at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:51)
at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:57)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.sql.SQLException: java.lang.NullPointerException
at io.seata.rm.datasource.exec.ExecuteTemplate.execute(ExecuteTemplate.java:115)
at io.seata.rm.datasource.exec.ExecuteTemplate.execute(ExecuteTemplate.java:50)
at io.seata.rm.datasource.PreparedStatementProxy.execute(PreparedStatementProxy.java:55)
at io.seata.rm.datasource.PreparedStatementProxy.lambda$execute$0(PreparedStatementProxy.java:55)
at io.seata.rm.datasource.exec.AbstractDMLBaseExecutor.executeAutoCommitFalse(AbstractDMLBaseExecutor.java:100)
at io.seata.rm.datasource.exec.AbstractDMLBaseExecutor.doExecute(AbstractDMLBaseExecutor.java:84)
at io.seata.rm.datasource.exec.BaseTransactionalExecutor.execute(BaseTransactionalExecutor.java:113)
at io.seata.rm.datasource.exec.ExecuteTemplate.execute(ExecuteTemplate.java:111)
at io.seata.rm.datasource.exec.ExecuteTemplate.execute(ExecuteTemplate.java:50)
at io.seata.rm.datasource.PreparedStatementProxy.execute(PreparedStatementProxy.java:55)
at jdk.internal.reflect.GeneratedMethodAccessor391.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59)
at com.sun.proxy.$Proxy243.execute(Unknown Source)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
at jdk.internal.reflect.GeneratedMethodAccessor567.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)
at com.sun.proxy.$Proxy241.update(Unknown Source)
at jdk.internal.reflect.GeneratedMethodAccessor567.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
at com.mysd.common.mybatis.SqlPrintInterceptor.intercept(ea:50)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
at com.sun.proxy.$Proxy241.update(Unknown Source)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
at jdk.internal.reflect.GeneratedMethodAccessor639.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)
at com.sun.proxy.$Proxy240.update(Unknown Source)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
at jdk.internal.reflect.GeneratedMethodAccessor650.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
... 68 common frames omitted
Caused by: java.lang.NullPointerException: null
at io.seata.rm.datasource.sql.struct.TableRecords.buildRecords(TableRecords.java:195)
at io.seata.rm.datasource.exec.BaseTransactionalExecutor.buildTableRecords(BaseTransactionalExecutor.java:402)
at io.seata.rm.datasource.exec.BaseInsertExecutor.afterImage(BaseInsertExecutor.java:77)
at io.seata.rm.datasource.exec.AbstractDMLBaseExecutor.executeAutoCommitFalse(AbstractDMLBaseExecutor.java:101)
at io.seata.rm.datasource.exec.AbstractDMLBaseExecutor.doExecute(AbstractDMLBaseExecutor.java:84)
at io.seata.rm.datasource.exec.BaseTransactionalExecutor.execute(BaseTransactionalExecutor.java:113)
at io.seata.rm.datasource.exec.ExecuteTemplate.execute(ExecuteTemplate.java:111)
... 110 common frames omitted

好多次都碰到

明明 insert 成功 返回插入成功1行

但是 Seata 报错 回滚

还是 NullPointerException

还不能复现出来

原因

1
2
3
String colName = resultSetMetaData.getColumnName(i);
ColumnMeta col = tmeta.getColumnMeta(colName);
int dataType = col.getDataType();

数据库在使用过程中修改过表结构 添加或删除了字段

Seata 的 tableMeta 没有更新 到 seata的更新时间后就没问题了

坑… 特别是 这些都是同事修改的数据库字段 自己没动

再次出现

直接写原因

数据库 有一列 仓库名称 列名 同事直接写成 name

Mybatis XML SQL 自动把 name 修改为 NAME

getColumnMeta(colName); 获取时是 根据列名获取

用 ‘NAME’ 肯定获取不到

Seata 的 Map 存储的是小写 ‘name’

不确定项目里面还有没有其它的大小写问题

直接修改 Seata 源码

io.seata.rm.datasource.sql.struct.TableMeta

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
	/**
* key: column name
*/

private Map<String, ColumnMeta> allColumns = new LinkedHashMap<>();
/**
* key: index name
*/
private Map<String, IndexMeta> allIndexes = new LinkedHashMap<>();

//修改为

/**
* key: column name
*/
private Map<String, ColumnMeta> allColumns = new LinkedCaseInsensitiveMap<>();
/**
* key: index name
*/
private Map<String, IndexMeta> allIndexes = new LinkedCaseInsensitiveMap<>();

//修改成不区分大小写的 Map