Hi,
I recently stumbled over a performance issue that I want to describe first in a simple example.
Imagine the following configuration:
Code:
<class name="sample.Entity" table="ENTITY">
<id name="id" type="long">
<column name="ENTITY_ID" not-null="true" />
<generator class="native" />
</id>
<set name="attributes" table="ENTITY_PROPERTY" lazy="false" cascade="all-delete-orphan">
<key column="ENTITY_ID" />
<many-to-many class="sample.Property" column="PROPERTY_ID" />
</set>
[...]
</class>
<class name="sample.Property" table="PROPERTY">
<id name="id" type="long">
<column name="PROPERTY_ID" not-null="true" />
<generator class="native" />
</id>
[...]
</class>
I am querying now a list of all of those entities:
Code:
select e from Entity
.
Every loaded entity can have a flexible amount of properties. Now I want to display every single property of every single entity. But this is expensive, because Hibernate now will first select all entities and then, for every single entity, select the properties joining them to the current entity.
For a hundred of entities, a hundred join-selects are executed.
Now that Hibernate knows that I do not want to lazy-load the Properties it could as well fetch the PROPERTY-TABLE in one statement. I believe this would increase the performance significantly. Would it?
A developer then could decide between loading lazily (only if needed) or performantly (if the collection is initialized anyway).
What do You think?
Regards,
Pvblivs