У меня есть этот запрос HQL.
Query query = session.createQuery(
"select inv from Invoice inv " +
"where 1=1 " +
"and inv.edited = false " +
"and businessSubscription.customer.user.id = :userId " +
"and inv.customerInvoice is null " +
"and inv.parentInvoice is null order by inv.id desc " +
"and exists (select 1 from InvoiceItem invItm where invItm.invoice.id = inv.id and invItm.product.id in (:productIdList))"
);
Зачем получать это исключение?
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: and near line 1, column 228 [select inv from Invoice inv where 1=1 and inv.edited = false and businessSubscription.customer.user.id = :userId and inv.customerInvoice is null and inv.parentInvoice is null order by inv.id desc and exists (select 1 from InvoiceItem invItm where invItm.invoice.id = inv.id and invItm.product.id in (:productIdList))]
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:91)
at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:109)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:304)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:203)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1800)
Где синтаксическая ошибка?
Мне кажется, проблема в invItm.invoice.id = inv.id
, можно использовать внешние псевдонимы в скобках?