TAILIEUCHUNG - The definitive guide to grails second edition - phần 6

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

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.