I have encountered a problem while using null as the key passing to the Hibernate.
I have named query
SELECT {sqp.*} FROM ezs_product {sqp}, ezs_price price , ezs_country_pl markup WHERE
sqp.product = :productNumber AND
NVL(sqp.options, ' ') = NVL(:productOption, ' ') AND
sqp.product = price.product AND
NVL(sqp.options, ' ') = NVL(price.options, ' ') AND
price.country = :country AND
price.currency = :currency AND
price.netprice IS NOT NULL AND
price.pricepmt IS NOT NULL AND
markup.country = price.country AND
markup.productline = sqp.productline
In the code I am setting 4 parameters where one of them (productOption) can be null so HashMap is created with entry ("productOption", null) in some cases.
However Hibernate throws exception at
org.hibernate.QueryException: Not all named parameters have been set: [productOption] [SELECT {sqp.*} FROM ezs_product {sqp}, ezs_price price , ezs_country_pl markup WHERE
sqp.product = :productNumber AND
NVL(sqp.options, ' ') = NVL(:productOption, ' ') AND
sqp.product = price.product AND
NVL(sqp.options, ' ') = NVL(price.options, ' ') AND
price.country = :country AND
price.currency = :currency AND
price.netprice IS NOT NULL AND
price.pricepmt IS NOT NULL AND
markup.country = price.country AND
markup.productline = sqp.productline]
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:291)
at org.hibernate.impl.SQLQueryImpl.verifyParameters(SQLQueryImpl.java:201)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:145)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:811)
I have found that problem is that for some reason Hibernate ignores null value for key in the HashMap and therefore "verifyParameters(boolean reserveFirstParameter) throws HibernateException" in AbstractQueryImpl.java throws error because it found less namedquery parameters set than expected.
Is it normal and if so - is there any reason why NULL key is not allowed for namedquery parameters ??
Thanks,
Petr.
Note : I know in this case NVL usage is useless as we can pass directly empty string to the SQL query...
|