GORM refresh() method not getting latest data from database

萝らか妹 提交于 2019-12-10 20:56:34

问题


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.

Ideas? Refreshing the "u" reference in the next HTTP request appears to work.


回答1:


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.



来源:https://stackoverflow.com/questions/1251792/gorm-refresh-method-not-getting-latest-data-from-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!