Hello,
I am using the latest Hibernate EJB 3.0 Implementation from trunk svn tree, this means Hibernate Core with Hibernate Annotations and Hibernate EntityManager. I have a problem with the following query:
Code:
//get the items which has a quanity ordered of >50
query = manager.createQuery("select items " +
"from Itemtable items " +
"join items.salespositions sales " +
"having sum(sales.quantity) > 60");
items = (ArrayList<Itemtable>)query.getResultList();
if (items.size() > 0) {
System.out.println("Items which has a quanitity ordered of >50");
for (Itemtable item : items) {
System.out.println("Id: " + item.getId() + " ,Name: " + item.getName());
}
} else {
System.out.println("Nothing found.");
}
I always get the following error:
Code:
Exception in thread "main" java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: having near line 1, column 67 [select items from Itemtable items join items.salespositions sales having sum(sales.quantity) > 60]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:596)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:94)
at HibernateTest.select(HibernateTest.java:67)
at HibernateTest.main(HibernateTest.java:22)
Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: having near line 1, column 67 [select items from Itemtable items join items.salespositions sales having sum(sales.quantity) > 60]
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.parse(QueryTranslatorImpl.java:258)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
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 org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:91)
what could that be? isn't the having clause a regular hql syntax?
Regards,
Christopher