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 6ea5246b..cdc23fec 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 @@ -245,9 +245,13 @@ public class RowSqlProvider { Object entity = ProviderUtil.getEntity(params); 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(ClassUtil.getUsefulClass(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 d2517e0e..ec8ffb83 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 @@ -82,19 +82,28 @@ public class DbTest { Map map2 = Db.selectFirstAndSecondColumnsAsMap("select * from tb_account"); System.out.println(map); System.out.println(map2); + assert map.equals(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); + try { + 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); + Account account3 = new Account(); + account3.setId(3L); + account3.setAge(4); + accounts.add(account3); + Db.updateEntitiesBatch(accounts); + }catch (Exception e){ + assert false; + } } }