diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/ModifyAttrsRecordProxyFactory.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/ModifyAttrsRecordProxyFactory.java index 7157bcdf..774efcac 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/ModifyAttrsRecordProxyFactory.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/ModifyAttrsRecordProxyFactory.java @@ -18,6 +18,7 @@ package com.mybatisflex.core.update; import com.mybatisflex.core.exception.FlexExceptions; import com.mybatisflex.core.util.ClassUtil; import com.mybatisflex.core.util.MapUtil; +import org.apache.ibatis.javassist.util.proxy.Proxy; import org.apache.ibatis.javassist.util.proxy.ProxyFactory; import org.apache.ibatis.javassist.util.proxy.ProxyObject; @@ -56,10 +57,16 @@ public class ModifyAttrsRecordProxyFactory { T proxyObject; try { proxyObject = (T) ClassUtil.newInstance(proxyClass); - ((ProxyObject) proxyObject).setHandler(new ModifyAttrsRecordHandler()); } catch (Exception e) { throw FlexExceptions.wrap(e, "请为实体类 %s 添加公开的无参构造器!", target.getCanonicalName()); } + if (proxyObject instanceof ProxyObject) { + ((ProxyObject) proxyObject).setHandler(new ModifyAttrsRecordHandler()); + } else if (proxyObject instanceof Proxy) { + ((Proxy) proxyObject).setHandler(new ModifyAttrsRecordHandler()); + } else { + throw FlexExceptions.wrap("为实体类 %s 设置字段更新处理器时出错,获取的实体类代理对象既不是 ProxyObject 的实例,也不是 Proxy 的实例", target.getCanonicalName()); + } return proxyObject; } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/UpdateWrapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/UpdateWrapper.java index f59c6b41..26731856 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/UpdateWrapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/UpdateWrapper.java @@ -15,12 +15,15 @@ */ package com.mybatisflex.core.update; +import com.mybatisflex.core.exception.FlexExceptions; import com.mybatisflex.core.query.QueryColumn; import com.mybatisflex.core.query.QueryCondition; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.util.LambdaGetter; import com.mybatisflex.core.util.LambdaUtil; import com.mybatisflex.core.util.UpdateEntity; +import org.apache.ibatis.javassist.util.proxy.Proxy; +import org.apache.ibatis.javassist.util.proxy.ProxyFactory; import org.apache.ibatis.javassist.util.proxy.ProxyObject; import java.io.Serializable; @@ -32,7 +35,14 @@ import java.util.Map; public interface UpdateWrapper extends PropertySetter>, Serializable { default Map getUpdates() { - ModifyAttrsRecordHandler handler = (ModifyAttrsRecordHandler) ((ProxyObject) this).getHandler(); + ModifyAttrsRecordHandler handler = null; + if (this instanceof ProxyObject) { + handler = (ModifyAttrsRecordHandler) ((ProxyObject) this).getHandler(); + } else if (this instanceof Proxy) { + handler = (ModifyAttrsRecordHandler) ProxyFactory.getHandler((Proxy) this); + } else { + throw FlexExceptions.wrap("获取实体类代理对象 %s 的字段更新处理器时出错,该对象既不是 ProxyObject 的实例,也不是 Proxy 的实例", this.getClass().getName()); + } return handler.getUpdates(); }