CHAPTER 13 Optimizing fetching and caching right thing. (Web site developers)

CHAPTER 13 Optimizing fetching and caching right thing. As an example, imagine a batch size of 20 and a total number of 119 uninitialized proxies that have to be loaded in batches. At startup time, Hibernate reads the mapping metadata and creates 11 batch loaders internally. Each loader knows how many proxies it can initialize: 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1. The goal is to minimize the memory consumption for loader creation and to create enough loaders that every possible batch fetch can be produced. Another goal is to minimize the number of SQL SELECTs, obviously. To initialize 119 proxies Hibernate executes seven batches (you probably expected six, because 6 x 20 > 119). The batch loaders that are applied are five times 20, one time 10, and one time 9, automatically selected by Hibernate. Batch fetching is also available for collections: If you now force the initialization of one bids collection, up to 10 more collections of the same type, if they re uninitialized in the current persistence context, are loaded right away: select items… select b.* from BID b where b.ITEM_ID in (?, ?, ?) In this case, you again have three Item objects in persistent state, and touching one of the unloaded bids collections. Now all three Item objects have their bids loaded in a single SELECT. Batch-size settings for entity proxies and collections are also available with annotations, but only as Hibernate extensions: @Entity @Table(name = “USERS”) @org.hibernate.annotations.BatchSize(size = 10) public class User { … } @Entity public class Item { … @OneToMany
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

Leave a Reply