-->
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: Native SQL query on joined subclass tables. Possible?
PostPosted: Wed Sep 07, 2005 2:22 pm 
Newbie

Joined: Wed Sep 07, 2005 12:45 pm
Posts: 1
Hibernate version 3.05:

Oracle version 9.2:

I am quite new to Hibernate and have stumbled right into a special situation.

I need to use native SQL to execute a query. The objects to be returned are instances of a subclass (say DomesticCat), based on the DB tables DBCAT and DBDOMCAT, joined on the column CatId.

I can use HQL without problems, all the necessary mappings are in place for that, but I need to use native SQL in order to specify an SQL hint.

My query would look somthing like this:

session.createSQLQuery(
"select {cat.*}, {domcat.*} from DBDOMCAT domcat
INNER JOIN DBCAT cat ON cat.catid=domcat.catid
WHERE cat.age > 5 and domcat.name like 'A%' ").
addEntity("domcat", DomesticCat.class).
list();

I need to join the tables in order to fully populate the DomesticCat object and also to specify search criteria on both tables. However Hibernate does not know the alias 'cat'. Is it at all possible to do what I am trying to do? If so, I hint or a link will be much appreciated.

- Thanks


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.