These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Return collections instead of object[] with sql-qry
PostPosted: Sat Sep 03, 2005 2:23 pm 
Beginner
Beginner

Joined: Sat Dec 20, 2003 5:09 pm
Posts: 38
Is this possible?

In the 3.1 beta documentation it seems possible:

Code:
<sql-query name="person">
<return alias="pers" class="Person"/>
<return-join alias="emp" property="pers.employments"/>
SELECT NAME AS {pers.*}, {emp.*}
FROM PERSON pers
LEFT OUTER JOIN EMPLOYMENT emp
ON pers.ID = emp.PERSON_ID
WHERE ID=?
</sql-query>


I've worked this into my own mapping with an example very similar to the above and have been playing with many different versions of it for the past few days. No matter what I do; however, I always get back an object array. What I really want is a fully initialized collection like one would get by doing a "fetch left join".

Another thing I think is a little odd is that as soon as I put in more joins, the debug output shows "lazy loading type select statements" for all collections, even though I've selected all the necessary data from the database in my native SQl qry. Can someone tell me if I'm on the wrong page with how this works?

Here are some examples of what I've been trying to do. Examples have been slimmed down to make them more clear

Code:
<class name = "Config" table="config">
        <id name="id" type="int" column="id" unsaved-value="0">
            <generator class="native"/>
        </id>

         <set name="selectBoxItems" lazy="false" fetch="join">
            <key column="config_id"/>
            <one-to-many class="DashSelectBoxItems"/>
        </set>

         <set name="data" lazy="false" fetch="join">
            <key column="config_id"/>
            <one-to-many class="Data"/>
        </set>

         <set name="notes" lazy="false" fetch="join">
            <key column="config_id"/>
            <one-to-many class="Notes"/>
        </set>

        <sql-query name="ConfigQuery">
            <return alias="C" class="Config"/>
            <return-join alias="ITEMS" property="C.selectBoxItems"/>
            <return-join alias="DATA"  property="C.data"/>
            <return-join alias="NOTES" property="C.notes"/>
                SELECT {C.*}, {ITEMS.*}, {DATA.*}, {NOTES.*}
                FROM dash_config C LEFT OUTER JOIN dash_select_box_items ITEMS ON (C.id = ITEMS.config_id)
                                   LEFT OUTER JOIN dash_tab_data DATA ON (C.id = DATA.config_id AND DATA.client_id = :CLIENT_ID)
                                   LEFT OUTER JOIN dash_notes NOTES ON (C.id = NOTES.config_id AND NOTES.client_id = :CLIENT_ID)
                ORDER BY C.tab_config_view_id, C.display_order, ITEMS.item
        </sql-query> 



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.