[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3226) HQL/JPQL query with where clause expression involving mulitple correlated subqueries does not parse

Bob Tiernay (JIRA) noreply at atlassian.com
Tue Apr 8 10:20:32 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3226?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_29972 ] 

Bob Tiernay commented on HHH-3226:
----------------------------------

Sorry for the lack of forethought and effort, but I've simplified it even more :)

SELECT 1 FROM com.cit.venulum.domain.entity.Account a WHERE ((SELECT 1 FROM com.cit.venulum.domain.entity.Trade t1) - 1) = 0

1297 [main] ERROR org.hibernate.impl.SessionFactoryImpl  - Error in named query: Account.findTotalInactiveCount
org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: query [SELECT 1 FROM com.cit.venulum.domain.entity.Account a WHERE ((SELECT 1 FROM com.cit.venulum.domain.entity.Trade t1) - 1) = 0]


> HQL/JPQL query with where clause expression involving mulitple correlated subqueries does not parse
> ---------------------------------------------------------------------------------------------------
>
>                 Key: HHH-3226
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3226
>             Project: Hibernate3
>          Issue Type: Bug
>    Affects Versions: 3.2.6
>            Reporter: Bob Tiernay
>
> The following named query will not parse:
> @NamedQuery(name = "Account.findTotalInactiveCount",  query = "SELECT COUNT(a) FROM Account a WHERE a.status.name NOT IN ('nst', 'ncl') AND a.seed = FALSE AND (SELECT CURRENT_DATE - MAX(t.date) FROM Trade t WHERE a.id IN (t.purchaser.id, t.seller.id)) > 183 AND ((SELECT SUM(t1.asset.price.value * t1.numberOfUnits) FROM Trade t1 WHERE t1.purchaser.id = a.id) - (SELECT SUM(t2.totalPrice * t2.numberOfUnits) FROM Trade t2 WHERE t2.seller.id = a.id) + (SELECT SUM(gl.debit) - SUM(gl.credit) FROM GeneralLedger gl WHERE gl.glAccount.id = 15 AND gl.account.id = a.id)) > 150.00")
> The error(s) issued from Hibernate are:
> 0    [main] ERROR org.hibernate.hql.PARSER  - <AST>:0:0: unexpected AST node: query
> 15   [main] ERROR org.hibernate.hql.PARSER  - <AST>:0:0: unexpected AST node: query
> For readability, I have formatted the query:
> SELECT	COUNT(a) 
> FROM 	Account a 
> WHERE 	a.status.name NOT IN ('nst', 'ncl') AND 
> 	a.seed = FALSE AND 
> 	(
> 		SELECT CURRENT_DATE - MAX(t.date) 
> 		FROM	Trade t 
> 		WHERE	a.id IN (t.purchaser.id, t.seller.id)
> 	) > 183 AND 
> 	(
> 		(SELECT	SUM(t1.asset.price.value * t1.numberOfUnits) 
> 		 FROM	Trade t1 
> 		 WHERE	t1.purchaser.id = a.id) - 
> 		
> 		(SELECT	SUM(t2.totalPrice * t2.numberOfUnits) 
> 		 FROM 	Trade t2 
> 		 WHERE 	t2.seller.id = a.id) + 
> 		
> 		(SELECT	SUM(gl.debit) - SUM(gl.credit) 
> 		 FROM	GeneralLedger gl 
> 		 WHERE 	gl.glAccount.id = 15 AND 
> 			gl.account.id = a.id)
> 	) > 150.00
> As an aside, I've tried reproducing this query using the Criteria API with no luck.  There doesn't seem to be a way to combine the results of subqueries for comparison.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list