TAILIEUCHUNG - Java Persistence with Hibernate 2nd phần 8

Prefetching bằng cách sử dụng một subselect là một tối ưu hóa mạnh mẽ, chúng tôi sẽ chỉ cho bạn một vài chi tiết về nó sau đó, khi chúng tôi đi bộ qua một kịch bản điển hình. Subselect lấy, tại thời điểm văn bản, chỉ có các bộ sưu tập, không phải cho các proxy thực thể. | 578 CHAPTER 13 Optimizing fetching and caching select i. from ITEM i select b. from BID b where in select from ITEM i In annotations you again have to use a Hibernate extension to enable this optimization @OneToMany @ private Set Bid bids new HashSet Bid Prefetching using a subselect is a powerful optimization we ll show you a few more details about it later when we walk through a typical scenario. Subselect fetching is at the time of writing available only for collections not for entity proxies. Also note that the original query that is rerun as a subselect is only remembered by Hibernate for a particular Session. If you detach an Item instance without initializing the collection of bids and then reattach it and start iterating through the collection no prefetching of other collections occurs. All the previous fetching strategies are helpful if you try to reduce the number of additional SELECTs that are natural if you work with lazy loading and retrieve objects and collections on demand. The final fetching strategy is the opposite of on-demand retrieval. Often you want to retrieve associated objects or collections in the same initial SELECT with a JOIN. Eager fetching with joins Lazy loading is an excellent default strategy. On other hand you can often look at your domain and data model and say Every time I need an Item I also need the seller of that Item. If you can make that statement you should go into your mapping metadata enable eager fetching for the seller association and utilize SQL joins class name Item table ITEM . many-to-one name seller class User column SELLER_ID update false fetch join class Hibernate now loads both an Item and its seller in a single SQL statement. For example Selecting a fetch strategy 579 Item item Item new Long 123 This operation triggers the following SQL SELECT select i. u. from ITEM i left outer join .

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.