-->
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.  [ 8 posts ] 
Author Message
 Post subject: ClassCastException Using createCriteria
PostPosted: Fri Jun 08, 2007 4:47 pm 
Newbie

Joined: Fri Jun 08, 2007 4:34 pm
Posts: 5
This simple example throws a ClassCastException on the criteria1.list()

Criteria criteria1 = hibSession.createCriteria(Traveler_Location.class).add(Expression.in("Org_CD",org_ID_list));

List locationCount = criteria1.list();

Hibernate: select this_.LOCAL_TRANS_NUM as LOCAL1_0_0_, this_.ORG_CD as ORG2_0_0_, this_.ISSUE_DATE as ISSUE3_0_0_ from TRAVELER_LOCATION this_ where this_.ORG_CD in (?, ?, ?)
- Unhandled Exception thrown: class java.lang.ClassCastException
- Servlet.service() for servlet action threw exception
java.lang.ClassCastException
at org.hibernate.type.StringType.toString(StringType.java:44)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:87)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1514)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1533)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at com.carlson.cwt.pmc.mapquest.World.getClientTravelers(World.java:65)
at com.carlson.cwt.pmc.mapquest.World.execute(World.java:171)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:534)



public class Traveler_Location implements Serializable
{
private String id;
private String Org_CD;
private Date Issue_Date;

public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}

public String getOrg_CD()
{
return Org_CD;
}
public void setOrg_CD(String org_CD)
{
Org_CD = org_CD;
}

public Date getIssue_Date()
{
return Issue_Date;
}
public void setIssue_Date(Date issue_date)
{
Issue_Date = issue_date;
}
}


<hibernate-mapping package="com.carlson.cwt.pmc.gdr_traveler_location">
<class name="Traveler_Location" table="TRAVELER_LOCATION">
<id name="id" column="LOCAL_TRANS_NUM" type="string" />
<property name="Org_CD" column="ORG_CD " type="string" />
<property name="Issue_Date" column="ISSUE_DATE" type="date" />
</class>
</hibernate-mapping>

I'm at a loss here. Any ideas? Thanks


Top
 Profile  
 
 Post subject: Problem in criteria criteria?
PostPosted: Fri Jun 08, 2007 5:38 pm 
Beginner
Beginner

Joined: Thu Jan 13, 2005 10:50 am
Posts: 30
Location: Minneapolis, MN
What is the type of the object
org_ID_list

I think that you are passing a type of List or arraylist to the argument
Org_CD, which is actually of type String. Therefore at the time of parsing of the query Hibernate tries to cast org_ID_list to String and thus the exception is thrown.

Please pass String type to the argument if you are not doing that


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 6:58 pm 
Newbie

Joined: Fri Jun 08, 2007 4:34 pm
Posts: 5
This is what I'm passing in org_ID_list:

Query qry0 = hibSession.createQuery("select Distinct M.Parent_Org_CD, M.Child_Org_CD, M.Effective_Date, M.Expiry_Date from Mv_Org_Rollup M, Traveler_Location L where M.Parent_Org_CD= ? and M.Child_Org_CD = L.Org_CD AND L.Issue_Date BETWEEN M.Effective_Date AND M.Expiry_Date").setString(0,org_cd);

List org_ID_list = qry0.list();


Top
 Profile  
 
 Post subject: Problems with list
PostPosted: Fri Jun 08, 2007 8:25 pm 
Beginner
Beginner

Joined: Thu Jan 13, 2005 10:50 am
Posts: 30
Location: Minneapolis, MN
What I think is that the list should be a list of Strings.
In ur case it could be a list of Object array. Because as per documentation the query.list() returns list of Object[] when the following condition is there
Quote:
. See the documentation for more details
Return the query results as a List. If the query contains multiple results pre row, the results are returned in an instance of Object[].


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 09, 2007 1:23 pm 
Newbie

Joined: Fri Jun 08, 2007 4:34 pm
Posts: 5
That was it! Thanks so much.


Top
 Profile  
 
 Post subject: Credits
PostPosted: Mon Jun 11, 2007 10:32 am 
Beginner
Beginner

Joined: Thu Jan 13, 2005 10:50 am
Posts: 30
Location: Minneapolis, MN
You can give credits if you found the solution useful ;)


Top
 Profile  
 
 Post subject: Re: Credits
PostPosted: Mon Jun 11, 2007 2:21 pm 
Newbie

Joined: Fri Jun 08, 2007 4:34 pm
Posts: 5
parasjain01 wrote:
You can give credits if you found the solution useful ;)


How do I go about that?


Top
 Profile  
 
 Post subject: Re: Credits
PostPosted: Mon Jun 11, 2007 2:23 pm 
Newbie

Joined: Fri Jun 08, 2007 4:34 pm
Posts: 5
weaselsuit wrote:
parasjain01 wrote:
You can give credits if you found the solution useful ;)


How do I go about that?


I see how now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.