-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL: Join onto Select View
PostPosted: Mon Jun 18, 2007 8:24 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:12 am
Posts: 39
Hibernate version: 3.1.3

Hi all,

I'm trying to optimise a query for mysql 5.x which was written like this:
Code:
SELECT  phraseSearchSummary.phrase
FROM    PhraseSearchSummary AS phraseSearchSummary
WHERE   phraseSearchSummary.phrase IN
    (SELECT innerPhraseSearchWord.phrase
     FROM PhraseSearchInventoryWord AS innerPhraseSearchWord
     WHERE innerPhraseSearchWord.word.word IN (:words)
     GROUP BY innerPhraseSearchWord.phrase
     HAVING COUNT(*) = :numberOfWords)


Into something like this, which tries to join onto a select view:

Code:
SELECT  phraseSearchSummary.phrase
FROM    PhraseSearchSummary AS phraseSearchSummary,
        (SELECT innerPhraseSearchWord.phrase AS phrase
        FROM PhraseSearchInventoryWord AS innerPhraseSearchWord
        WHERE innerPhraseSearchWord.word.word IN (:words)
        GROUP BY innerPhraseSearchWord.phrase
        HAVING COUNT(*) = :numberOfWords) AS wordSummary
WHERE phraseSearchSummary.phrase.id = wordSummary.phrase.id


The new query when run in SQL runs over 40x faster however the HQL version above fails to load when hibernate starts up with the standard error message saying "Errors in named queries". Is this kind of query possible?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 8:32 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
NO.
HQL subqueries may occur only in the select or where clauses.
So, we cannot have inline views ( subquery in from clause) in HQL.
Try using createSQLQuery instead.

---------------------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 8:47 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:12 am
Posts: 39
ok, thanks for the quick reply...looks like i'll be doing some custom sql


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

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.