From a2e6e97a6ed23fc831a5f634a96472aac6070c19 Mon Sep 17 00:00:00 2001
From: caohdgege <1170050364@qq.com>
Date: Mon, 28 Dec 2020 21:13:26 +0800
Subject: [PATCH] bugfix: fix getGeneratedKeys may get history pk (#3418)

---
 changes/1.5.0.md                                       |  1 +
 changes/en-us/1.5.0.md                                 |  1 +
 .../io/seata/rm/datasource/AbstractStatementProxy.java | 10 +---------
 3 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/changes/1.5.0.md b/changes/1.5.0.md
index 4822cfcc1..281f5052b 100644
--- a/changes/1.5.0.md
+++ b/changes/1.5.0.md
@@ -27,6 +27,7 @@ Seata 鏄竴娆惧紑婧愮殑鍒嗗竷寮忎簨鍔¤В鍐虫柟妗堬紝鎻愪緵楂樻€ц兘鍜岀畝鍗�
   - [[#3293](https://github.com/seata/seata/pull/3293)] 淇閰嶇疆缂撳瓨鑾峰彇鍊兼椂绫诲瀷涓嶅尮閰嶇殑bug
   - [[#3241](https://github.com/seata/seata/pull/3241)] 绂佹鍦ㄥSQL鐨勬儏鍐典笅浣跨敤 limit 鍜� order by 璇硶
   - [[#3406](https://github.com/seata/seata/pull/3406)] 淇褰揷onfig.txt涓寘鍚壒娈婂瓧绗︽椂锛岄敭鍊煎鏃犳硶琚帹涓妌acos
+  - [[#3418](https://github.com/seata/seata/pull/3418)] 淇 getGeneratedKeys 鍙兘浼氬彇鍒板巻鍙茬殑涓婚敭鐨勯棶棰�
 
 
 
diff --git a/changes/en-us/1.5.0.md b/changes/en-us/1.5.0.md
index 52ad711c6..52bbf4e2e 100644
--- a/changes/en-us/1.5.0.md
+++ b/changes/en-us/1.5.0.md
@@ -27,6 +27,7 @@
   - [[#3293](https://github.com/seata/seata/pull/3293)] configuration cache get value cast exception
   - [[#3241](https://github.com/seata/seata/pull/3241)] forbidden use order by or limit in multi sql
   - [[#3406](https://github.com/seata/seata/pull/3406)] fix the value can not be push to nacos when special charset in config.txt
+  - [[#3418](https://github.com/seata/seata/pull/3418)] fix getGeneratedKeys may get history pk
 
 
   ### optimize锛� 
diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractStatementProxy.java b/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractStatementProxy.java
index 584138e23..32b132cff 100644
--- a/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractStatementProxy.java
+++ b/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractStatementProxy.java
@@ -42,11 +42,6 @@ public abstract class AbstractStatementProxy<T extends Statement> implements Sta
      */
     protected T targetStatement;
 
-    /**
-     * The generated keys cached row set.
-     */
-    private CachedRowSet generatedKeysRowSet;
-
     /**
      * The Target sql.
      */
@@ -249,11 +244,8 @@ public abstract class AbstractStatementProxy<T extends Statement> implements Sta
 
     @Override
     public ResultSet getGeneratedKeys() throws SQLException {
-        if (generatedKeysRowSet != null) {
-            return generatedKeysRowSet;
-        }
         ResultSet rs = targetStatement.getGeneratedKeys();
-        generatedKeysRowSet = RowSetProvider.newFactory().createCachedRowSet();
+        CachedRowSet generatedKeysRowSet = RowSetProvider.newFactory().createCachedRowSet();
         generatedKeysRowSet.populate(rs);
         return generatedKeysRowSet;
     }
-- 
GitLab