We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.5.9
JDK21 SpringBoot 3.4.0 PostgreSQL 16
已配置LocalDateTime序列化
public JacksonLocalDateTimeModule() { // 对于LocalDateTime的序列化和反序列化 super(PackageVersion.VERSION); this.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern( DatePattern.NORM_DATETIME_PATTERN))); this.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN))); this.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DatePattern.NORM_TIME_PATTERN))); this.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN))); this.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN))); this.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DatePattern.NORM_TIME_PATTERN))); }
当发生更新时添加@Version到updateTime,数据类型为LocalDateTime
@Version
updateTime
LocalDateTime
生成的SQL为
SQL
UPDATE iam_tenant SET create_time='2024-12-11T16:02:05', update_time='2024-12-12T11:00:58.736136700', create_user='zy', update_user='zy', iam_tenant_name='测试', iam_tenant_code='TEST1', iam_tenant_sort=1, iam_tenant_owner_role='67bf65dfd620129f422dfec0517a872c', iam_tenant_id_chain='d6d1c8bbe16446b2b3c12addbd355a92' WHERE id='d6d1c8bbe16446b2b3c12addbd355a92' AND update_time='2024-12-12T10:53:35'
会在更新时自动为updateTime赋值。
第二次进行修改时
UPDATE iam_tenant SET create_time='2024-12-11T16:02:05', update_time='2024-12-12T11:01:02.427611600', create_user='zy', update_user='zy', iam_tenant_name='测试', iam_tenant_code='TEST18', iam_tenant_sort=1, iam_tenant_owner_role='67bf65dfd620129f422dfec0517a872c', iam_tenant_id_chain='d6d1c8bbe16446b2b3c12addbd355a92' WHERE id='d6d1c8bbe16446b2b3c12addbd355a92' AND update_time='2024-12-12T11:00:58'
updateTime取到的作为版本号的值就缺少了秒后的八位 导致无法正常更新。
希望能够给出在哪里可以重写 自动更新实体的方法 或者LocalDateTime重写的问题。
No response
The text was updated successfully, but these errors were encountered:
找到目前乐观锁插件的映射如下:
private static class VersionFactory { private static final Map<Class<?>, Function<Object, Object>> VERSION_FUNCTION_MAP = new HashMap(); private VersionFactory() { } public static Object getUpdatedVersionVal(Class<?> clazz, Object originalVersionVal) { Function<Object, Object> versionFunction = (Function)VERSION_FUNCTION_MAP.get(clazz); return versionFunction == null ? originalVersionVal : versionFunction.apply(originalVersionVal); } static { VERSION_FUNCTION_MAP.put(Long.TYPE, (Function)(version) -> (Long)version + 1L); VERSION_FUNCTION_MAP.put(Long.class, (Function)(version) -> (Long)version + 1L); VERSION_FUNCTION_MAP.put(Integer.TYPE, (Function)(version) -> (Integer)version + 1); VERSION_FUNCTION_MAP.put(Integer.class, (Function)(version) -> (Integer)version + 1); VERSION_FUNCTION_MAP.put(Date.class, (Function)(version) -> new Date()); VERSION_FUNCTION_MAP.put(Timestamp.class, (Function)(version) -> new Timestamp(System.currentTimeMillis())); VERSION_FUNCTION_MAP.put(LocalDateTime.class, (Function)(version) -> LocalDateTime.now()); VERSION_FUNCTION_MAP.put(Instant.class, (Function)(version) -> Instant.now()); } }
当前的情况分析是,updateTime是LocalDateTime,但是采用了Timestamp作为更新实体的类型了?
Sorry, something went wrong.
No branches or pull requests
确认
当前程序版本
3.5.9
问题描述
当前环境
JDK21
SpringBoot 3.4.0
PostgreSQL 16
已配置LocalDateTime序列化
出现的问题
当发生更新时添加
@Version
到updateTime
,数据类型为LocalDateTime
生成的
SQL
为会在更新时自动为
updateTime
赋值。第二次进行修改时
updateTime
取到的作为版本号的值就缺少了秒后的八位导致无法正常更新。
希望能够给出在哪里可以重写 自动更新实体的方法 或者LocalDateTime重写的问题。
详细堆栈日志
No response
The text was updated successfully, but these errors were encountered: