-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: null parameter in HashMap<String,String> ???
PostPosted: Fri Nov 02, 2007 12:34 pm 
Newbie

Joined: Fri Nov 02, 2007 12:26 pm
Posts: 1
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...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.