Bulletproof web design - Selecting a fetch strategy initialized only on demand,
Wednesday, February 6th, 2008Selecting a fetch strategy initialized only on demand, and you have no other strategy configured, a particular procedure may well execute dozens or even hundreds of queries to get all the data you require. You need the right strategy to avoid executing too many SQL statements. If you switch from the default strategy to queries that eagerly fetch data with joins, you may run into another problem, the Cartesian product issue. Instead of executing too many SQL statements, you may now (often as a side effect) create statements that retrieve too much data. You need to find the middle ground between the two extremes: the correct fetching strategy for each procedure and use case in your application. You need to know which global fetch plan and strategy you should set in your mapping metadata, and which fetching strategy you apply only for a particular query (with HQL or Criteria). We now introduce the basic problems of too many selects and Cartesian products and then walk you through optimization step by step. The n+1 selects problem The n+1 selects problem is easy to understand with some example code. Let s assume that you don t configure any fetch plan or fetching strategy in your mapping metadata: Everything is lazy and loaded on demand. The following example code tries to find the highest Bids for all Items (there are many other ways to do this more easily, of course): List
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.