hibernate - java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Calendar -
i trying convert string calendar,but giving exception.
here code:-
public list<classa> getdata(string fromdatetime, string todatetime, integer apiid) throws daoexception, parseexception { calendar cal1 = calendar.getinstance(); calendar cal2 = calendar.getinstance(); dateformat df=new simpledateformat("yyyy-mm-dd hh:mm:ss"); cal1.settime(df.parse(fromdatetime)); cal2.settime(df.parse(todatetime)); return findbycriteria(restrictions.eq("apiid", apiid), restrictions.between("searchgenerationtime", fromdatetime, todatetime)); }
please can told me wrong in code ?? lets assume fromdatetime & todatetime user input 2014-04-02 19:24:43 & 2014-04-03 12:03:51 respectively. thanks.
edited:- here stack trace
java.lang.classcastexception: java.lang.string cannot cast java.util.calendar @ org.hibernate.type.descriptor.java.calendartypedescriptor.unwrap(calendartypedescriptor.java:40) @ org.hibernate.type.descriptor.sql.timestamptypedescriptor$1.dobind(timestamptypedescriptor.java:53) @ org.hibernate.type.descriptor.sql.basicbinder.bind(basicbinder.java:91) @ org.hibernate.type.abstractstandardbasictype.nullsafeset(abstractstandardbasictype.java:283) @ org.hibernate.type.abstractstandardbasictype.nullsafeset(abstractstandardbasictype.java:278) @ org.hibernate.loader.loader.bindpositionalparameters(loader.java:1873) @ org.hibernate.loader.loader.bindparametervalues(loader.java:1844) @ org.hibernate.loader.loader.preparequerystatement(loader.java:1716) @ org.hibernate.loader.loader.doquery(loader.java:801) @ org.hibernate.loader.loader.doqueryandinitializenonlazycollections(loader.java:274) @ org.hibernate.loader.loader.dolist(loader.java:2542) @ org.hibernate.loader.loader.listignorequerycache(loader.java:2276) @ org.hibernate.loader.loader.list(loader.java:2271) @ org.hibernate.loader.criteria.criterialoader.list(criterialoader.java:119) @ org.hibernate.impl.sessionimpl.list(sessionimpl.java:1716) @ org.hibernate.impl.criteriaimpl.list(criteriaimpl.java:347) @ com.via.database.util.daoutil.findbycriteriainternal(daoutil.java:227) @ com.via.database.util.daoutil.findbycriteria(daoutil.java:198) @ com.via.database.dao.hibernate.generichibernatedao.findbycriteria(generichibernatedao.java:175) @ com.eos.accounts.database.dao.hibernate.hotelsearcherrequestresponsedao.getdata(hotelsearcherrequestresponsedao.java:53) @ com.eos.hotels.hotelsearcherutility.gethotelsearchrequestresopnsedata(hotelsearcherutility.java:50) @ com.eos.b2c.ui.b2ccallcenternavigation.dogetextension(b2ccallcenternavigation.java:9568) @ com.eos.b2c.ui.b2ccallcenternavigation.doget(b2ccallcenternavigation.java:5851) @ javax.servlet.http.httpservlet.service(httpservlet.java:617) @ javax.servlet.http.httpservlet.service(httpservlet.java:717) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:290) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ com.eos.accounts.usermanagerfilter.dofilter(usermanagerfilter.java:972) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:235) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:233) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:191) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:470) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:127) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:109) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:293) @ org.apache.coyote.http11.http11processor.process(http11processor.java:861) @ org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:606) @ org.apache.tomcat.util.net.jioendpoint$worker.run(jioendpoint.java:489) @ java.lang.thread.run(thread.java:701)
i think return statement should follows:
return findbycriteria(restrictions.eq("apiid", apiid), restrictions.between("searchgenerationtime", cal1, cal2));
Comments
Post a Comment