-->
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.  [ 3 posts ] 
Author Message
 Post subject: Binding error in 'in' clause using HQL
PostPosted: Tue Aug 26, 2008 12:35 am 
Newbie

Joined: Tue Aug 26, 2008 12:29 am
Posts: 2
Location: Wilmington
I have a named query as following:
* @hibernate.query name="BusinessUnit.getBusinessUnitsForIDList" query=" select distinct \
* new com.cscinfo.cdsapp.model.hbm.BusinessUnit (bu.id, bu.businessUnitName, bu.dfltBusunitNameServerProfid)\
* from BusinessUnit bu\
* where bu.id in (:businessUnitIdList)"


When running the code, I have a string parameter whose value resolves to '5902', '95'. But the binding is throwing error since 'bu.id' is of type long.

26 Aug 2008 00:24:45,704 INFO HostTemplateDAOHibernate strForParameter : '5902', '95'
Hibernate:
select
distinct businessun0_.businessUnitId as col_0_0_,
businessun0_.businessUnitName as col_1_0_,
businessun0_.dfltBusunitNameServerProfid as col_2_0_
from
businessUnit businessun0_
where
businessun0_.businessUnitId in (
?
)
26 Aug 2008 00:24:45,704 INFO LongType could not bind value ''5902', '95'' to parameter: 1; java.lang.String
26 Aug 2008 00:24:45,736 ERROR [cdsapp] Servlet.service() for servlet cdsapp threw exception
java.lang.ClassCastException: java.lang.String
at org.hibernate.type.LongType.set(LongType.java:42)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:116)
at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:38)
at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:491)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1563)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.cscinfo.cdsapp.dao.hibernate.HostTemplateDAOHibernate.checkAndRemoveDefaultRelationShip(HostTemplateDAOHibernate.java:454)
at com.cscinfo.cdsapp.dao.hibernate.HostTemplateDAOHibernate.deleteBUToBeDeleted(HostTemplateDAOHibernate.java:426)



Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 26, 2008 1:58 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You need to convert the strings to longs before setting the "businessUnitIdList" parameter.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 26, 2008 8:49 am 
Newbie

Joined: Tue Aug 26, 2008 12:29 am
Posts: 2
Location: Wilmington
Hi Nordborg,
The list that I am using to construct the string for 'in' clause already consists of longs. The problem is that I still have to construct a string out of those longs to make it seem like a list of values for 'in' clause.
However, I figured out the problem later in the day, by using
setParameterList(String, Collection) method of Query class.
Thanks for looking into the problem though.


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

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.