History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: HHH-3414
Type: New Feature New Feature
Status: Open Open
Priority: Major Major
Assignee: Steve Ebersole
Reporter: Steve Ebersole
Votes: 3
Watchers: 4
Operations

If you were logged in you would be able to see more operations.
Hibernate Core

fetch profiles

Created: 04/Aug/08 04:38 PM   Updated: 09/Sep/08 11:56 PM
Component/s: core, metamodel
Affects Version/s: None
Fix Version/s: 3.4

Time Tracking:
Not Specified

Requires Release Note: Affirmative


 Description  « Hide
The concept of fetch profiles as we are discussing here is basically to allow users to dynamically affect the mapped fetching strategy for associations at runtime.

Consider the following example:

<class name="Person">
    ...
    <set name="addresses" lazy="true" fetch="subselect" ...>
        ...
    </set>
</class>

<class name="Address">
    ...
</class>

This follows the normal recommendation to map associations as lazy and use a dynamic fetching strategy (ala HQL/Criteria) to modify this lazy behavior at runtime.

The fetaure discussed here would allow the same behavior for loading as well:
<hibernate-mapping>
    <fetch-profile name="person-details">
        <fetch path="Person.addresses" style="join"/>
    </fetch-profile>
</hibernate-mapping>
Or:
<hibernate-mapping>
<class name="Person">
    ...
    <fetch-profile name="person-details">
        <fetch path="addresses" style="join"/>
    </fetch-profile>

    <set name="addresses" lazy="true" fetch="subselect" ...>
        ...
    </set>
</class>
</hibernate-mapping>

Now, doing:
session.enableFetchProfile( "person-details" ).get( Person.class, 1 )...

will load Person#1 as well as their addresses in a single joined query.

 All   Comments   Work Log   Change History   FishEye      Sort Order: Ascending order - Click to sort in descending order
Steve Ebersole - 20/Aug/08 11:45 AM
Types of fetches:
1) join - an outer join fetch
2) select - a subsequent select fetch (n+1)
3) subselect - support for this requires significant refactoring to the subselect loading code, and as such it is not planned for the initial feature release.


Gary Sargent - 09/Sep/08 05:25 PM
It would be nice to be able to do be able to control things at this level too for formula based properties. These can contain expensive SQL queries and it would be nice to be able to set the fetch mode on such a lazy formula property so it is either retrieved via select (n+1) or fetched non-lazily (equivalent to join).

You could then enable these expensive formula properties only when needed.

Steve Ebersole - 09/Sep/08 11:56 PM
I *think* you are trying to describe what are generally called fetch groups. This is in fact possible today (though in a limited fashion : with only a single fetch group) using Hibernate's bytecode enhancement tasks.