-->
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.  [ 2 posts ] 
Author Message
 Post subject: Unexpected Token doing inner join on Subquery?
PostPosted: Thu Sep 16, 2010 1:59 pm 
Beginner
Beginner

Joined: Tue Feb 03, 2009 4:33 pm
Posts: 21
I'm trying to execute the following:
Code:
getSession().createQuery("select distinct b from Bid b inner join (select x.auction, x.amount, count(x) cnt from Bid x where x.status in ('CONFIRMED','WINNER') group by x.auction, x.amount order by cnt limit 1) z on z.amount = b.amount and z.auction = b.auction where b.auction = :auction and b.status in ('CONFIRMED','WINNER') order by b.received").setParameter("auction", auction).setMaxResults(1).list();


(In a nutshell, this should return the "lowest unique bid" in a sort of "reverse-auction" thing I'm working on.).

Hibernate is throwing the following exception:
Code:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 64 [select distinct b from com.lbs.entities.Bid b inner join (select x.auction, x.amount, count(x) cnt from com.lbs.entities.Bid x where x.status in ('CONFIRMED','WINNER') group by x.auction, x.amount order by cnt limit 1) z on z.amount = b.amount and z.auction = b.auction where b.auction = :auction and b.status in ('CONFIRMED','WINNER') order by b.received]


line 1, column 64 appears to be the opening parenthesis of the first subquery. Can anyone tell me what I'm doing wrong here, or else help me refactor this into a criteria-based query?

[edit] Oh yeah, also, instead of "x.status in ('CONFIRMED','WINNER')", it should be something like "x.status in (BidStatus.CONFIRMED, BidStatus.WINNER)", which I can do with Criteria (using a @Type annotation and a custom EnumUserType class), but can't figure out how to do in HQL. Any help with that would definitely be an added bonus :-)


Top
 Profile  
 
 Post subject: Re: Unexpected Token doing inner join on Subquery?
PostPosted: Tue Jun 14, 2011 8:54 am 
Newbie

Joined: Fri Nov 13, 2009 2:47 pm
Posts: 3
I'm also hitting a similar issue with a named query:

@NamedQuery(
name = "PublishedRun.findLatestPublishedRuns",
query = "select r from PublishedRun r " +
"INNER JOIN (SELECT r2.runIndex, r2.scenarioName, MAX(r2.startTime) " +
"FROM PublishedRun r2 GROUP BY r2.scenarioName) v " +
"ON v.runIndex = r.runIndex"
)


TEST :: 2011-06-14 08:38:41,086 [main] ERROR org.hibernate.hql.PARSER (56) - line 1:88: unexpected token: (
TEST :: 2011-06-14 08:38:41,088 [main] DEBUG org.hibernate.hql.ast.ErrorCounter (51) - line 1:88: unexpected token: (
line 1:88: unexpected token: (


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.