GORM refresh()方法不会从数据库获取最新数据 [英] GORM refresh() method not getting latest data from database
问题描述
保存更改后的用户名(使用 flush:true
)后,以下表达式的计算结果为false:
After saving a changed user name (using flush:true
), the following expression evaluates to false:
User.get(u.getId()).name == u.refresh().name
左手拿起已更改的用户名,而右手返回旧值。
The left hand side picks up the changed user name while the right hand side return the "old" value.
想法?刷新下一个HTTP请求中的u引用似乎有效。
Ideas? Refreshing the "u" reference in the next HTTP request appears to work.
推荐答案
这是在一个事务中完成的吗?如果你的代码在一个事务中执行,那么即使使用 flush:true
也不会立即保存对数据库的更改。交易结束时对域对象的更改只会在交易结束时刷新。
Is this being done within a transaction? If your code is executing within a transaction then even using flush: true
won't immediately persist changes to the database. Changes to domain objects made within a transaction are only flushed when the transaction ends.
这篇关于GORM refresh()方法不会从数据库获取最新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!