Skip to content
New issue

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

EntityPrepareModifyEvent 修改字段后 update 未生效 #505

Closed
MoonBottle opened this issue May 7, 2024 · 16 comments
Closed

EntityPrepareModifyEvent 修改字段后 update 未生效 #505

MoonBottle opened this issue May 7, 2024 · 16 comments

Comments

@MoonBottle
Copy link

image

监听了 EntityPrepareModifyEvent 事件,修改了某个字段
image

最终执行的 sql 还是原先的字段,请问下这个事件不能修改字段值么
image

image

@zhou-hao
Copy link
Member

@MoonBottle
Copy link
Author

MoonBottle commented May 11, 2024

hsweb-framework 版本:4.0.17-SNAPSHOT
easy-ormb 版本:4.1.2-SNAPSHOT
版本信息

步骤:
1、update 前设置了 -1
image
2、EntityPrepareModifyEvent 事件中给更新前后的实体分别设置成了-2 和 -3
image
3、debug 看 entry.setValue 是塞成功了,取到了 -3
image
4、最终执行的 sql 是 -1
image

另外发现个现象:
第 1 步 update 前不塞值的话,只在第 2 步中塞值,第 4 步最终执行的 sql 不会有相关字段
image

@MoonBottle
Copy link
Author

在这个代码仓库中复现了:https://github.com/MoonBottle/hsweb-framework
1、update 前赋值
2、监听事件并修改变量值
3、最终执行的 sql
image

@zhou-hao
Copy link
Member

试试这个PR hs-web/hsweb-framework#288

@MoonBottle
Copy link
Author

MoonBottle commented May 14, 2024

试试这个PR hs-web/hsweb-framework#288

测试了下,修改的值是预期的 -3,大佬👍
image

@MoonBottle
Copy link
Author

MoonBottle commented May 14, 2024

但是今天又发现了一个新的现象,感觉似乎有点问题,步骤如下:
新增了一个 testColumn2 字段
1、使用 .setNull(EventTestEntity::getTestColumn2)
2、预期的 sql 是正常的执行了 setnull
3、但是在 EntityModifyEvent 中 after 对象的 testColumn2 字段值变成了 0,预期这里也是 null 值

测试代码还是在这个仓库中:https://github.com/MoonBottle/hsweb-framework

image

@zhou-hao
Copy link
Member

zhou-hao commented May 14, 2024

字段类型是包装器类型还是基本数据类型

我再看看..

@zhou-hao
Copy link
Member

再试试

@zhou-hao
Copy link
Member

不过目前不能通过EntityPrepareModifyEvent设置null值

@MoonBottle
Copy link
Author

不过目前不能通过EntityPrepareModifyEvent设置null值

抱歉,我有点没说清楚,现在这个现象和 EntityPrepareModifyEvent 没有关系了,是一个单独的问题

刚才又试了下,setNull 似乎不生效了,最终执行的 sql 中没有 set null 的语句

已确认刷新过 maven

image

@zhou-hao
Copy link
Member

image image

@zhou-hao
Copy link
Member

代码 没同步完? hs-web/hsweb-framework@74d7421

@MoonBottle
Copy link
Author

代码 没同步完? hs-web/hsweb-framework@74d7421

抱歉抱歉,我没注意到 PR 有新的 commit,代码没同步完

同步后测试成功了,大佬🐂🍺,非常感谢!🙏

@zhou-hao
Copy link
Member

好的。没有问题我就合并了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants