diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java index 64ac87b2..574c1458 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java @@ -26,6 +26,7 @@ import com.mybatisflex.core.row.RowMapper; import com.mybatisflex.core.table.TableInfo; import com.mybatisflex.core.table.TableInfoFactory; import com.mybatisflex.core.util.ArrayUtil; +import org.apache.ibatis.javassist.util.proxy.ProxyObject; import java.util.*; @@ -244,8 +245,13 @@ public class RowSqlProvider { FlexAssert.notNull(entity, "entity can not be null"); + Class entityClass = entity.getClass(); + //如果是代理mybatis代理对象 + if(entity instanceof ProxyObject){ + entityClass = entityClass.getSuperclass(); + } // 该 Mapper 是通用 Mapper 无法通过 ProviderContext 获取,直接使用 TableInfoFactory - TableInfo tableInfo = TableInfoFactory.ofEntityClass(entity.getClass()); + TableInfo tableInfo = TableInfoFactory.ofEntityClass(entityClass); // 执行 onUpdate 监听器 tableInfo.invokeOnUpdateListener(entity); diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DbTest.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DbTest.java index d06aec07..d2517e0e 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DbTest.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DbTest.java @@ -17,9 +17,12 @@ package com.mybatisflex.test; import com.mybatisflex.core.MybatisFlexBootstrap; +import com.mybatisflex.core.audit.AuditManager; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.row.Db; import com.mybatisflex.core.row.Row; +import com.mybatisflex.core.update.UpdateWrapper; +import com.mybatisflex.core.util.UpdateEntity; import org.apache.ibatis.session.Configuration; import org.junit.Assert; import org.junit.BeforeClass; @@ -28,6 +31,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import javax.sql.DataSource; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -78,7 +82,19 @@ public class DbTest { Map map2 = Db.selectFirstAndSecondColumnsAsMap("select * from tb_account"); System.out.println(map); System.out.println(map2); - Assert.assertEquals(map,map2); - } + } + @Test + public void test03() { + Account account = UpdateEntity.of(Account.class,1); + account.setAge(1); + List accounts = new ArrayList<>(); + accounts.add(account); + Account account2 = UpdateEntity.of(Account.class,2); + account2.setAge(2); + UpdateWrapper updateWrapper = UpdateWrapper.of(account2); + updateWrapper.setRaw("age","age+1"); + accounts.add(account2); + Db.updateEntitiesBatch(accounts); + } }