Web design programs - CHAPTER 13 Optimizing fetching and caching annotation (which

CHAPTER 13 Optimizing fetching and caching annotation (which is the default in Java Persistence). Eager join fetching of single- ended associations, unlike eager outer-join fetching of collections, doesn t create a Cartesian product problem. The Cartesian product problem The opposite of the n+1 selects problem are SELECT statements that fetch too much data. This Cartesian product problem always appears if you try to fetch several parallel collections. Let s assume you ve made the decision to apply a global fetch=”join” setting to the bids collection of an Item (despite our recommendation to use global prefetching and a dynamic join-fetching strategy only when necessary). The Item class has other collections: for example, the images. Let s also assume that you decide that all images for each item have to be loaded all the time, eagerly with a fetch=”join” strategy: If you map two parallel collections (their owning entity is the same) with an eager outer-join fetching strategy, and load all Item objects, Hibernate executes an SQL SELECT that creates a product of the two collections: select item.*, bid.*, image.* from ITEM item left outer join BID bid on item.ITEM_ID = bid.ITEM_ID left outer join ITEM_IMAGE image on item.ITEM_ID = image.ITEM_ID Look at the resultset of that query, shown in figure 13.6. This resultset contains lots of redundant data. Item 1 has three bids and two images, item 2 has one bid and one image, and item 3 has no bids and no images. The size of the product depends on the size of the collections you re retrieving: 3 times 2, 1 times 1, plus 1, total 8 result rows. Now imagine that you have 1,000
We recommend high quality webhost to host and run your jsp application: christian web host services.

Leave a Reply