<class name="Item" table="ITEM">
    ...
    <many-to-one name="seller"
                 class="User"
                 column="SELLER_ID"
                 update="false"
                 not-null="true"
                 lazy="no-proxy"/>
     ...
</class>

Fetch strategy:

1. batch fetching:

Batch fetching is often called a blind-guess optimization.

<class name="User"
       table="USERS"
       batch-size="10">
...
</class>
You’re telling Hibernate to prefetch up to 10 uninitialized proxies in a single SQL
SELECT, if one proxy must be initialized.如果有100条记录的话,就fetch 10遍

2. Prefetching collections with subselects:

<class name="Item" table="ITEM">
    ...
    <set name="bids"
         inverse="true"
         fetch="subselect">
        <key column="ITEM_ID"/>
        <one-to-many class="Bid"/>
    </set>
</class>
Hibernate now initializes all bids collections for all loaded Item objects, as soon
as you force the initialization of one bids collection.

 

3. Eager fetching with joins

<class name="Item" table="ITEM">
    ...
    <many-to-one name="seller"
                 class="User"
                 column="SELLER_ID"
                 update="false"
                 fetch="join"/>
</class>

Obviously,  the  seller  is  no  longer  lazily  loaded  on  demand,  but  immediately.Hence, a fetch="join" disables lazy loading. If you only enable eager fetching with  lazy="false",  you  see  an  immediate  second  SELECT.  With  fetch="join",you get the seller loaded in the same single SELECT.