The following is a query that isn't particularly useful, but it demonstrates what we perceive to be HQL failing. The actual query we want to run is a bit more complex, but when we whittled it down to something very basic it still fails.
The following fails:
Code:
session.createQuery(
   "select P from Product P where 4 > (" +
      "select (" +
         "select count(U) from User U" +
      ")" +
      " + count(PE) from Person PE" +
   ")"
).list()
The following works:
Code:
session.createQuery(
   "select P from Product P where 4 > (" +
      "select (" +
         "1" +
      ")" +
      " + count(PE) from Person PE" +
   ")"
).list()
By themselves these queries return the following:
Code:
session.createQuery("select count(U) from User U").uniqueResult()
returns 1
Code:
session.createQuery("select count(PE) from Person PE").uniqueResult()
returns 1
Our failing query above shows the following in console:
Code:
May 1, 2008 11:16:27 AM org.hibernate.hql.ast.ErrorCounter reportError
SEVERE: <AST>:0:0: unexpected AST node: query
May 1, 2008 11:16:27 AM org.hibernate.hql.ast.ErrorCounter reportError
SEVERE:  right-hand operand of a binary operator was null
With this stack trace
Code:
org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: query [select P from bpf.database.products.Product P where 4 > (select (select count(U) from bpf.database.userAccounts.User U) + count(PE) from bpf.database.people.Person PE)]
   at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
   at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
   at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:235)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
   at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
   at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
   at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
   at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
   at $Proxy18.createQuery(Unknown Source)
   at bpf.database.products.ProductManager.getLowStock(ProductManager.java:32)
   at bpf.database.products.test.TestProduct.testLowStock(TestProduct.java:156)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at junit.framework.TestCase.runTest(TestCase.java:168)
   at junit.framework.TestCase.runBare(TestCase.java:134)
   at junit.framework.TestResult$1.protect(TestResult.java:110)
   at junit.framework.TestResult.runProtected(TestResult.java:128)
   at junit.framework.TestResult.run(TestResult.java:113)
   at junit.framework.TestCase.run(TestCase.java:124)
   at junit.framework.TestSuite.runTest(TestSuite.java:232)
   at junit.framework.TestSuite.run(TestSuite.java:227)
   at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Is this an issue in HQL or are we misunderstanding something about HQL? Has anyone seen a similar problem before?