问题
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