From 77f657df32d37334afa8a4244f2c7c839a4ce286 Mon Sep 17 00:00:00 2001 From: jay <75509151@qq.com> Date: Wed, 7 Jun 2023 11:55:34 +0800 Subject: [PATCH] =?UTF-8?q?fix=20id=E7=94=9F=E6=88=90:=20=E5=AD=98?= =?UTF-8?q?=E5=9C=A8id=E5=88=99=E4=B8=8D=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/config/id/SnowflakeIdGenerator.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/id/SnowflakeIdGenerator.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/id/SnowflakeIdGenerator.java index 75add318..e9bfcb3d 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/id/SnowflakeIdGenerator.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/id/SnowflakeIdGenerator.java @@ -2,6 +2,9 @@ package cc.iotkit.data.config.id; import cc.iotkit.common.utils.SnowflakeIdGeneratorUtil; import java.io.Serializable; +import java.lang.reflect.Field; +import java.util.Objects; + import org.hibernate.HibernateException; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.id.IdentifierGenerator; @@ -18,6 +21,17 @@ public class SnowflakeIdGenerator implements IdentifierGenerator { @Override public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException { + Field id = null; + try { + id = o.getClass().getDeclaredField("id"); + id.setAccessible(true); + Object val = id.get(o); + if (Objects.nonNull(val)){ + return (Serializable) val; + } + } catch (NoSuchFieldException | IllegalAccessException e) { + + } return SnowflakeIdGeneratorUtil.getInstanceSnowflake().nextId(); } }