-->
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: Help! Native SQL query to retrieve derived object
PostPosted: Tue Jul 25, 2006 4:12 pm 
Beginner
Beginner

Joined: Tue Nov 15, 2005 6:56 pm
Posts: 39
Using Hibernate 3.1

I have a case where I have a mapping file for a particular table, and a pojo to represent that table. The mapping file defines two subclasses that are represented by pojos and other respective tables in the DB.

I want to execute a native SQL query directly in code (not a named SQL query) to get me a list of one of the derived objects.


My hbm file looks something like this for the root table:

Code:
       
        <property name="buId" type="long" column="bu_id"/>
        ....
        <subclass name="com.mycompany.DerivedA" discriminator-value="2">
         <join table="DERIVEDA">
            <key column="deriveda_id"/>
                                ...
                        </join>
         </subclass>

        <subclass name="com.mycompany.DerivedB" discriminator-value="3">
         <join table="DERIVEDB">
            <key column="derivedb_id"/>
                                ...
                        </join>
         </subclass>


I'm trying something like this:

Code:
Session s = IDM.getHibernateSession();
SQLQuery q = s.createSQLQuery( "select {root.*}, {derivedA.*}, {derivedB.*} ....");
q.addEntity("root", Root.class);
q.addJoin("derivedA", "com.mycompany.DerivedA");
q.addJoin("derivedB", "com.mycompany.DerivedB");


Is this the right way to go about doing this? I believe the second parameters to my addJoin method are wrong, but I don't know what to set them to. Plus, so I need to have all the classes stated in the SELECT clause or just the derived one I'm trying to fetch? I'm going down the path of specifying all the joins etc. since I'm tyring to get the derived object and Hibernate will complain that it can't find a property in the mapping file if I don't. I'm assuming this is the right way to do it.


Any help is greatly appreciated.

-Sam


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.