Hibernate fetching strategy to optimize ---

1. lazy loading

   Like lazy loading

       Configuring the mapping file class in the class label lazy attribute: The default is true, when you configure the time is false, even if you use session.load he would send SQL statements after you call this method, instead of using your the resulting query object when it sends SQL statements

   Associate-level lazy loading

       Configuring the lazy attribute set and many-to-one mapping file class: The default is true, that is, when you query an object is, he will not even his query with the associated object when you use these associated objects of the time will send SQL statements to query

2. crawling strategy

   fetch and lazy on set

        fetch is used to control the format of the sql statement: value --- join, select (default value), subselect, when using join the lazy fail, that query object when he first sql statement select A join B on ..... it will be a one-time associate objects can also check out. The subselect When the value is, the plurality of query objects and their associated object is transmitted a sql statement nested queries. select the default values, circumstances and the associated level lazy loading is similar, but more a value extra, and lazy, when you select this value, a property associated with the output of the class, he would query this property alone, so instead of properties are poor out

   fetch and lazy on the many-to-one

       The role and set the same, but fetch values ​​only select and join, usage, too, lazy value of proxy, false, no-proxy (basically do not), when the value of proxy, depending on whether the delay in loading with lazy on the class corresponding class, for example: many relationship between customers and contacts, lazy on the many-to-one contact mapping file for the proxy, if lazy loading customer queries contact, it depends on the customer to map file lazy on class

3. Batch fetching

Set in a set in batch-size = "number of queries," When you find out the customer list, traversing customers get their contact time will be a one-time query multiple customer contacts, rather than each customer contacts are once inquiry

Guess you like

Origin www.cnblogs.com/zy-Luo/p/11041728.html