Exception thrown as "unexpected AST node: query [select e.gnteGkey from
com.navis.argo.business.extract.Guarantee as e where () order by e.gnteGkey DESC]"
when an empty predicate added to the query.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-4445
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4445
Project: Hibernate Core
Issue Type: Bug
Components: query-hql
Environment: Hibernate-3
MySQL-5.1
Reporter: Ramakrishnan
Getting the following exception when I try to add an empty predicate to the query.
Error Trace:
Hibernate query failed for HQL "select e.gnteGkey from Guarantee as e where ()
order by e.gnteGkey DESC" with message: unexpected AST node: query [select e.gnteGkey
from com.navis.argo.business.extract.Guarantee as e where () order by e.gnteGkey DESC]
Here is the code piece that shows the query composition:
-------------------------Code start----------------------------------------
TableQueryFactory tableQueryFactory = new TableQueryFactory();
DomainQuery query = tableQueryFactory.createDomainQuery(getTable(),
getTableDefinition());
UserContext context = getUserContext();
PredicateIntf oacOrCreditPreauthorize =
PredicateFactory.in(ArgoExtractField.GNTE_GUARANTEE_TYPE,
new GuaranteeTypeEnum[]{GuaranteeTypeEnum.OAC,
GuaranteeTypeEnum.CREDIT_PREAUTHORIZE});
PredicateIntf waiver = PredicateFactory.in(ArgoExtractField.GNTE_GUARANTEE_TYPE,
new GuaranteeTypeEnum[]{GuaranteeTypeEnum.WAIVER});
Disjunction disjunction = PredicateFactory.disjunction();
if (ArgoPrivs.UNIT_GUARANTEE_VIEW.isAllowed(context) ||
ArgoPrivs.UNIT_GUARANTEE_EDIT.isAllowed(context)) {
disjunction.add(oacOrCreditPreauthorize);
}
if (ArgoPrivs.UNIT_WAIVER_VIEW.isAllowed(context) ||
ArgoPrivs.UNIT_WAIVER_EDIT.isAllowed(context)) {
disjunction.add(waiver);
}
return query.addDqPredicate(disjunction);
-------------------------Code end---------------------------------------
In the above code if both the conditions are not satisfied, the disjunction is simply
added without any values( shown as where() in the hql query) and the above mentioned error
is thrown when this query is executed.
I could able to solve this by initiating the "disjunction" variable to
"null" and at last by adding it to the query if disjunction != null.
It will be helpful if this could be handled at Hibernate level, as if the disjunction
doesn't have any predicate values , it could be omitted from the query.
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira