[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3908) Expose way to fully control fetching in native-sql queries in API

Steve Ebersole (JIRA) noreply at atlassian.com
Fri May 8 12:17:14 EDT 2009


Expose way to fully control fetching in native-sql queries in API
-----------------------------------------------------------------

                 Key: HHH-3908
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3908
             Project: Hibernate Core
          Issue Type: New Feature
          Components: core
            Reporter: Steve Ebersole
             Fix For: 3.5


Currently, in order to fully control fetching in native-sql queries, users must revert to using a named sql query (at least the xml, not sure if the annotations variety supports as well).  We alreasy have all the objects/contracts in place to handle this for the named queries, just need to clean-up and properly document them.

The current API calls to deal with this are the overloaded SQLQuery#addJoin methods.  Ideally I'd see these changed to return the representation of the join-fetch to be configured; but addJoin already defines a return : the query itself :(  So probably we will need new methods like addFetch:

1) public JoinFetch addFetch(String alias, String ownerAlias, String ownerProperty)
2) public JoinFetch addFetch(String alias, String ownerAlias, String ownerProperty, LockMode lockMode)

interface JoinFetch {
    public void addPropertyMapping(String propertyName, String sqlAlias);
}

This can be expanded to the "root returns" as well (currently the overloaded #addEntity methods):
public RootReturn addRoot(String alias, Class entityClass)
etc...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQLQuery query = session.createSQLQuery(
        "select c.cust_id as cid, " +
        "        c.cust_name as cname, " +
        "        o.order_id as oid, " +
        "        o.order_num as onum " + 
        " from customer c " +
        "        inner join orders o " +
        "                on c.cust_id = o.cust_id"
);
query.addRoot( "c", Customer.class )
        .addPropertyMapping( "id", "cid" )
        .addPropertyMapping( "name", "cname" );
query.addFetch( "o", "c", "orders" )
        .addPropertyMapping( "id", "oid" )
        .addPropertyMapping( "orderNumber", "onum" );
...


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list