Những gợi ý của kỳ họp tự động Flushing 1 album def 2 3 4 5 = (1) = "Thay đổi" def otherAlbums = ("%% Thay đổi") khẳng định (album) | CHAPTER 10 GORM 271 Listing 10-29. The Implications of Automatic Session Flushing 1 def album 1 2 Change It 3 def otherAlbums Change 4 5 assert album Now you may think that because you never called save on the album there is no way it could possibly have been persisted to the database right Wrong. As soon as you load the album instance it immediately becomes a managed object as far as Hibernate is concerned. Since Hibernate is by default configured to flush the session when a query runs the Session is flushed on line 3 when the findAllWhereTitleLike method is called and the Album instance is persisted. The Hibernate Session caches changes and pushes them to the database only at the latest possible moment. In the case of automatic flushing this is at the end of a transaction or before a query runs that might be affected by the cached changes. You may consider the behavior of automatic flushing to be a little odd but if you think about it it depends very much on your expectations. If the object weren t flushed to the database then the change made to it on line 2 would not be reflected in the results. That may not be what you re expecting either Let s consider another example where automatic flushing may present a few surprises. Take a look at the code in Listing 10-30. Listing 10-30. Another Implication of Automatic Session Flushing def album 1 Change It In Listing 10-16 an instance of the Album class is looked up and the title is changed but the save method is never called. You may expect that since save was never called the Album instance will not be persisted to the database. However you d be wrong again. Hibernate does automatic dirty checking and flushes any changes to the persistent instances contained within the Session. This may be what you were expecting in the first place. However one thing to consider is that if you simply allow this to happen then Grails built-in