In my application I have lazy collections.
I load ALL objects from database.
Consider standard parent-child example:
<class entity-name="Placement" abstract="false" lazy="false" discriminator-value="Placement" table="`placement`">
...
<many-to-one name="owner" entity-name="Placement" cascade="merge,persist,save-update,lock,refresh" lazy="false" insert="true" update="true" not-null="false">
<column not-null="false" unique="false" name="`owner_id`"/>
</many-to-one>
<bag name="children" fetch="subselect" lazy="true" cascade="merge,persist,save-update,lock,refresh" inverse="true">
<key update="true">
<column name="`owner_id`" not-null="false" unique="false"/>
</key>
<one-to-many entity-name="Placement"/>
</bag>
...
</class>
I begin transaction.
First I read all placements into session. Then I touch placement.children. Really all information needed to instantiate placement.children collections is in session. But hibernate issues separate select to instantiate them - it's OK.
Then I commit transaction.
The same situation is for another relations: elements of collections are in session but hibernate issues complicated selects to instantiate them.
Really for my application loading time is not optimal it is can be optimized by means of smart placement.children collection loading.
The question is:
Is it possible to configure hibernate that it loads only ids of elements in collection and then looks up elements by id in session?
Thanks in advance.
PS: the second-level cache is not solution for me: I need to speed up time of initial loading of big amount of data.
|