how to solve the Class cast exception in HibernateTemplate's findByCriteria()?
This is the method of Dao class that is throwing Exception:
I did not used any Integer here. Even the phone number property is
also a String as it can contain +,() Symbols sometimes.
public List<StudentDetails> retriveStudents( String studentFirstName, String studentLastName,String studentEmail, String studentPhoneNum)
logger.info("AddStudentDao retriveStudents():- START");
List<StudentDetails> nonTerminatedStudentsList = null;
//List<UserLocationMapping> userLocationMappings = null;
Set<Integer> studentIdSet = new HashSet<Integer>();
try
DetachedCriteria objmCriteria = DetachedCriteria.forClass(StudentDetails.class);
//objmCriteria.createAlias("studentDetails", "UserDetails");
objmCriteria.add(Restrictions.ne("loginId", Constants.SUPER_ADMIN));
if (!Utilities.IsEmpty(studentFirstName))
objmCriteria.add(Restrictions.like("firstName", "%" + studentFirstName + "%"));
if (!Utilities.IsEmpty(studentLastName))
objmCriteria.add(Restrictions.like("lastName", "%" + studentLastName + "%"));
if (!Utilities.IsEmpty(studentEmail))
objmCriteria.add(Restrictions.like("email", "%" + studentEmail + "%"));
if (!Utilities.IsEmpty((studentPhoneNum)))
objmCriteria.add(Restrictions.like("phoneNumber", "%" + studentPhoneNum + "%"));
nonTerminatedStudentsList = hibernateTemplate.findByCriteria(objmCriteria);//*****EXCEPTION RAISING*****(Line number 216)
if (studentIdSet != null && studentIdSet.size() > 0)
nonTerminatedStudentsList = getStudents(studentIdSet);
catch (Exception e)
logger.error(" AddStudentDao retriveUsers :- ", e);
logger.info("AddStudentDao retriveUsers():- END");
return nonTerminatedStudentsList;
This is supposed to return a List of StudentDetails objects but the
method used in this scenario is raising an Exception. Hope somebody
can help me.
and the exception is shown like this:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at org.hibernate.type.StringType.toString(StringType.java:67)
at org.hibernate.type.NullableType.nullSafeToString(NullableType.java:117)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:158)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1732)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1703)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1593)
at org.hibernate.loader.Loader.doQuery(Loader.java:696)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2232)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2124)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1597)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
at org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1056)
at org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1046)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1039)
at com.pss.admin.dao.student.AddStudentDao.retriveStudents(AddStudentDao.java:216)
at com.pss.admin.dao.student.AddStudentDao$$FastClassByCGLIB$$41df7ff.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:618)
at com.pss.admin.dao.student.AddStudentDao$$EnhancerByCGLIB$$25e36467_2.retriveStudents(<generated>)
at com.pss.admin.bo.student.SaveStudentService.retriveStudents(SaveStudentService.java:91)
at com.pss.admin.controller.student.StudentController.retriveStudents(StudentController.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
java hibernate spring-mvc classcastexception
add a comment |
This is the method of Dao class that is throwing Exception:
I did not used any Integer here. Even the phone number property is
also a String as it can contain +,() Symbols sometimes.
public List<StudentDetails> retriveStudents( String studentFirstName, String studentLastName,String studentEmail, String studentPhoneNum)
logger.info("AddStudentDao retriveStudents():- START");
List<StudentDetails> nonTerminatedStudentsList = null;
//List<UserLocationMapping> userLocationMappings = null;
Set<Integer> studentIdSet = new HashSet<Integer>();
try
DetachedCriteria objmCriteria = DetachedCriteria.forClass(StudentDetails.class);
//objmCriteria.createAlias("studentDetails", "UserDetails");
objmCriteria.add(Restrictions.ne("loginId", Constants.SUPER_ADMIN));
if (!Utilities.IsEmpty(studentFirstName))
objmCriteria.add(Restrictions.like("firstName", "%" + studentFirstName + "%"));
if (!Utilities.IsEmpty(studentLastName))
objmCriteria.add(Restrictions.like("lastName", "%" + studentLastName + "%"));
if (!Utilities.IsEmpty(studentEmail))
objmCriteria.add(Restrictions.like("email", "%" + studentEmail + "%"));
if (!Utilities.IsEmpty((studentPhoneNum)))
objmCriteria.add(Restrictions.like("phoneNumber", "%" + studentPhoneNum + "%"));
nonTerminatedStudentsList = hibernateTemplate.findByCriteria(objmCriteria);//*****EXCEPTION RAISING*****(Line number 216)
if (studentIdSet != null && studentIdSet.size() > 0)
nonTerminatedStudentsList = getStudents(studentIdSet);
catch (Exception e)
logger.error(" AddStudentDao retriveUsers :- ", e);
logger.info("AddStudentDao retriveUsers():- END");
return nonTerminatedStudentsList;
This is supposed to return a List of StudentDetails objects but the
method used in this scenario is raising an Exception. Hope somebody
can help me.
and the exception is shown like this:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at org.hibernate.type.StringType.toString(StringType.java:67)
at org.hibernate.type.NullableType.nullSafeToString(NullableType.java:117)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:158)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1732)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1703)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1593)
at org.hibernate.loader.Loader.doQuery(Loader.java:696)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2232)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2124)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1597)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
at org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1056)
at org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1046)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1039)
at com.pss.admin.dao.student.AddStudentDao.retriveStudents(AddStudentDao.java:216)
at com.pss.admin.dao.student.AddStudentDao$$FastClassByCGLIB$$41df7ff.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:618)
at com.pss.admin.dao.student.AddStudentDao$$EnhancerByCGLIB$$25e36467_2.retriveStudents(<generated>)
at com.pss.admin.bo.student.SaveStudentService.retriveStudents(SaveStudentService.java:91)
at com.pss.admin.controller.student.StudentController.retriveStudents(StudentController.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
java hibernate spring-mvc classcastexception
can you post yourStudentDetails
class
– benjamin c
Nov 12 '18 at 5:18
add a comment |
This is the method of Dao class that is throwing Exception:
I did not used any Integer here. Even the phone number property is
also a String as it can contain +,() Symbols sometimes.
public List<StudentDetails> retriveStudents( String studentFirstName, String studentLastName,String studentEmail, String studentPhoneNum)
logger.info("AddStudentDao retriveStudents():- START");
List<StudentDetails> nonTerminatedStudentsList = null;
//List<UserLocationMapping> userLocationMappings = null;
Set<Integer> studentIdSet = new HashSet<Integer>();
try
DetachedCriteria objmCriteria = DetachedCriteria.forClass(StudentDetails.class);
//objmCriteria.createAlias("studentDetails", "UserDetails");
objmCriteria.add(Restrictions.ne("loginId", Constants.SUPER_ADMIN));
if (!Utilities.IsEmpty(studentFirstName))
objmCriteria.add(Restrictions.like("firstName", "%" + studentFirstName + "%"));
if (!Utilities.IsEmpty(studentLastName))
objmCriteria.add(Restrictions.like("lastName", "%" + studentLastName + "%"));
if (!Utilities.IsEmpty(studentEmail))
objmCriteria.add(Restrictions.like("email", "%" + studentEmail + "%"));
if (!Utilities.IsEmpty((studentPhoneNum)))
objmCriteria.add(Restrictions.like("phoneNumber", "%" + studentPhoneNum + "%"));
nonTerminatedStudentsList = hibernateTemplate.findByCriteria(objmCriteria);//*****EXCEPTION RAISING*****(Line number 216)
if (studentIdSet != null && studentIdSet.size() > 0)
nonTerminatedStudentsList = getStudents(studentIdSet);
catch (Exception e)
logger.error(" AddStudentDao retriveUsers :- ", e);
logger.info("AddStudentDao retriveUsers():- END");
return nonTerminatedStudentsList;
This is supposed to return a List of StudentDetails objects but the
method used in this scenario is raising an Exception. Hope somebody
can help me.
and the exception is shown like this:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at org.hibernate.type.StringType.toString(StringType.java:67)
at org.hibernate.type.NullableType.nullSafeToString(NullableType.java:117)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:158)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1732)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1703)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1593)
at org.hibernate.loader.Loader.doQuery(Loader.java:696)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2232)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2124)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1597)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
at org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1056)
at org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1046)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1039)
at com.pss.admin.dao.student.AddStudentDao.retriveStudents(AddStudentDao.java:216)
at com.pss.admin.dao.student.AddStudentDao$$FastClassByCGLIB$$41df7ff.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:618)
at com.pss.admin.dao.student.AddStudentDao$$EnhancerByCGLIB$$25e36467_2.retriveStudents(<generated>)
at com.pss.admin.bo.student.SaveStudentService.retriveStudents(SaveStudentService.java:91)
at com.pss.admin.controller.student.StudentController.retriveStudents(StudentController.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
java hibernate spring-mvc classcastexception
This is the method of Dao class that is throwing Exception:
I did not used any Integer here. Even the phone number property is
also a String as it can contain +,() Symbols sometimes.
public List<StudentDetails> retriveStudents( String studentFirstName, String studentLastName,String studentEmail, String studentPhoneNum)
logger.info("AddStudentDao retriveStudents():- START");
List<StudentDetails> nonTerminatedStudentsList = null;
//List<UserLocationMapping> userLocationMappings = null;
Set<Integer> studentIdSet = new HashSet<Integer>();
try
DetachedCriteria objmCriteria = DetachedCriteria.forClass(StudentDetails.class);
//objmCriteria.createAlias("studentDetails", "UserDetails");
objmCriteria.add(Restrictions.ne("loginId", Constants.SUPER_ADMIN));
if (!Utilities.IsEmpty(studentFirstName))
objmCriteria.add(Restrictions.like("firstName", "%" + studentFirstName + "%"));
if (!Utilities.IsEmpty(studentLastName))
objmCriteria.add(Restrictions.like("lastName", "%" + studentLastName + "%"));
if (!Utilities.IsEmpty(studentEmail))
objmCriteria.add(Restrictions.like("email", "%" + studentEmail + "%"));
if (!Utilities.IsEmpty((studentPhoneNum)))
objmCriteria.add(Restrictions.like("phoneNumber", "%" + studentPhoneNum + "%"));
nonTerminatedStudentsList = hibernateTemplate.findByCriteria(objmCriteria);//*****EXCEPTION RAISING*****(Line number 216)
if (studentIdSet != null && studentIdSet.size() > 0)
nonTerminatedStudentsList = getStudents(studentIdSet);
catch (Exception e)
logger.error(" AddStudentDao retriveUsers :- ", e);
logger.info("AddStudentDao retriveUsers():- END");
return nonTerminatedStudentsList;
This is supposed to return a List of StudentDetails objects but the
method used in this scenario is raising an Exception. Hope somebody
can help me.
and the exception is shown like this:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at org.hibernate.type.StringType.toString(StringType.java:67)
at org.hibernate.type.NullableType.nullSafeToString(NullableType.java:117)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:158)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1732)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1703)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1593)
at org.hibernate.loader.Loader.doQuery(Loader.java:696)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2232)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2124)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1597)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
at org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1056)
at org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1046)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1039)
at com.pss.admin.dao.student.AddStudentDao.retriveStudents(AddStudentDao.java:216)
at com.pss.admin.dao.student.AddStudentDao$$FastClassByCGLIB$$41df7ff.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:618)
at com.pss.admin.dao.student.AddStudentDao$$EnhancerByCGLIB$$25e36467_2.retriveStudents(<generated>)
at com.pss.admin.bo.student.SaveStudentService.retriveStudents(SaveStudentService.java:91)
at com.pss.admin.controller.student.StudentController.retriveStudents(StudentController.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
java hibernate spring-mvc classcastexception
java hibernate spring-mvc classcastexception
asked Nov 12 '18 at 5:15
Shaik BajivaliShaik Bajivali
267
267
can you post yourStudentDetails
class
– benjamin c
Nov 12 '18 at 5:18
add a comment |
can you post yourStudentDetails
class
– benjamin c
Nov 12 '18 at 5:18
can you post your
StudentDetails
class– benjamin c
Nov 12 '18 at 5:18
can you post your
StudentDetails
class– benjamin c
Nov 12 '18 at 5:18
add a comment |
1 Answer
1
active
oldest
votes
Sorry guys.. My bad.
the constant in the first Restriction is an integer.
Thank you.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256284%2fhow-to-solve-the-class-cast-exception-in-hibernatetemplates-findbycriteria%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sorry guys.. My bad.
the constant in the first Restriction is an integer.
Thank you.
add a comment |
Sorry guys.. My bad.
the constant in the first Restriction is an integer.
Thank you.
add a comment |
Sorry guys.. My bad.
the constant in the first Restriction is an integer.
Thank you.
Sorry guys.. My bad.
the constant in the first Restriction is an integer.
Thank you.
answered Nov 12 '18 at 5:46
Shaik BajivaliShaik Bajivali
267
267
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256284%2fhow-to-solve-the-class-cast-exception-in-hibernatetemplates-findbycriteria%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
can you post your
StudentDetails
class– benjamin c
Nov 12 '18 at 5:18