java.lang.IllegalArgumentException: java.lang.ClassCastException@1cb6d9bb
at sun.reflect.GeneratedMethodAccessor1029.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45005)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:65)
at org.hibernate.transform.AliasToBeanResultTransformer.transformTuple(AliasToBeanResultTransformer.java:95)
at org.hibernate.hql.internal.HolderInstantiator.instantiate(HolderInstantiator.java:95)
at org.hibernate.loader.custom.CustomLoader.getResultList(CustomLoader.java:395)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2263)
at org.hibernate.loader.Loader.list(Loader.java:2258)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:331)
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1697)
at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:225)
at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:156)
at org.jeecgframework.core.common.dao.impl.GenericBaseCommonDao.findPageInfoByParse(GenericBaseCommonDao.java:582)
at org.jeecgframework.core.common.service.impl.CommonServiceImpl.findPageInfoByParse(CommonServiceImpl.java:508)
at com.yiyibang.internethospital.service.impl.PhysicianVisitsOrderServiceImpl.listPhysicianVisitsOrdersPageInfo(PhysicianVisitsOrderServiceImpl.java:48)
at sun.reflect.GeneratedMethodAccessor1006.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45005)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy117.listPhysicianVisitsOrdersPageInfo(Unknown Source)
at com.yiyibang.internethospital.controller.rest.PhysicianVisitsOrderRestController.listPhysicianVisitsOrders(PhysicianVisitsOrderRestController.java:181)
at sun.reflect.GeneratedMethodAccessor1005.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45005)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:747)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:676)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
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.jeecgframework.core.aop.GZipFilter.doFilter(GZipFilter.java:111)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:140)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:150)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
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.core.StandardContextValve.invoke(StandardContextValve.java:41002)
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:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
JAVA 类中 属性类型 映射 Mybatis 或 hibernate 异常
/**
* PO 代码
/
public class PhyOrderQO extends HmPhysicianVisitsOrdersDO implements Serializable {
/**
* 有效时长,秒数
*/
private Integer validTime;
public Integer getValidTime() {
return validTime;
}
public void setValidTime(Integer validTime) {
this.validTime = validTime;
}
}
# SQLXML 代码
<select id="listPhysicianVisitsOrdersPageInfo">
SELECT
t.id id,
t.company_id companyId,
t.consult_type consultType,
t.created_id createdId,
t.create_time createTime,
t.doctor_id doctorId,
t.doctor_name doctorName,
t.doctor_source_no_id doctorSourceNoId,
t.enabled enabled,
t.evaluate_flag evaluateFlag,
t.last_operated_id lastOperatedId,
t.last_operate_time lastOperateTime,
t.order_code orderCode,
t.order_flag orderFlag,
t.order_price orderPrice,
t.order_status orderStatus,
t.patient_age patientAge,
t.patient_card_no patientCardNo,
t.patient_card_type patientCardType,
t.patient_id patientId,
t.patient_id_card patientIdCard,
t.patient_name patientName,
t.patient_phone patientPhone,
t.patient_sex patientSex,
t.pay_status payStatus,
t.phrase_text phraseText,
t.prescription_orders_group_id prescriptionOrdersGroupId,
t.question_descr questionDescr,
t.reject_descr rejectDescr,
t.reject_reason rejectReason,
t.remark remark,
t.sort_field sortField,
t.see_date seeDate,
t.dept_name deptName,
TIMESTAMPDIFF( SECOND,( SELECT DATE_ADD( t.create_time, INTERVAL 24 HOUR )), NOW() ) AS validTime
from hm_physician_visits_orders t
<where>
<if test="doctorId != null">
t.doctor_id =#{doctorId,jdbcType=VARCHAR}
</if>
<if test="companyId != null">
AND t.company_id =#{companyId,jdbcType=VARCHAR}
</if>
<if test="patientName != null and patientName != '' ">
AND t.patient_name LIKE CONCAT('%',#{patientName,jdbcType=VARCHAR},'%')
</if>
<if test="patientId != null and patientId != '' ">
AND t.patient_id = #{patientId,jdbcType=VARCHAR}
</if>
<if test="payStatus != null and payStatus != '' ">
AND t.pay_status =#{payStatus,jdbcType=VARCHAR}
</if>
<if test="orderStatus != null and orderStatus != ''">
AND t.order_status= #{orderStatus,jdbcType=VARCHAR}
</if>
<if test="orderCode != null and orderCode != ''">
AND t.order_code = #{orderCode,jdbcType=VARCHAR}
</if>
<if test="consultType != null and consultType != ''">
AND t.consult_type=#{consultType,jdbcType=VARCHAR}
</if>
<if test="startTime != null and startTime != ''">
AND t.create_time <![CDATA[ >= ]]> #{startTime,jdbcType=VARCHAR}
</if>
<if test="endTime != null and endTime != '' ">
AND t.create_time <![CDATA[ <= ]]> #{endTime,jdbcType=VARCHAR}
</if>
</where>
order by t.last_operate_time desc ,t.sort_field desc
</select>
此处是
TIMESTAMPDIFF( SECOND,( SELECT DATE_ADD( t.create_time, INTERVAL 24 HOUR )), NOW() ) AS validTime
映射
validTime 属性报错
改为 BigInteger 即可
后续如果还是遇到类似的问题,不知道用什么包装类型接收,可以用 Object 作为类型。
或 接收 SQL 查询结果时,用 map ,然后打断电调试可以看出具体当前 字段的子类型。
public class PhyOrderQO extends HmPhysicianVisitsOrdersDO implements Serializable {
/**
* 有效时长,秒数
*/
private BigInteger validTime;
public BigInteger getValidTime() {
return validTime;
}
public void setValidTime(BigInteger validTime) {
this.validTime = validTime;
}
}
SELECT
TIME_TO_SEC(TIMEDIFF('2018-09-30 19:38:45', '2018-08-23 10:13:01')) AS DIFF_SECOND1, -- 秒
UNIX_TIMESTAMP('2018-09-30 19:38:45')-UNIX_TIMESTAMP('2018-08-23 10:13:01') AS DIFF_SECOND2, -- 秒
TIMESTAMPDIFF(SECOND,'2018-08-23 10:13:01','2018-09-30 19:38:45') AS DIFF_SECOND3, -- 秒
TIMESTAMPDIFF(MINUTE,'2018-08-23 10:13:01','2018-09-30 19:38:45') AS DIFF_MINUTE, -- 分
TIMESTAMPDIFF(HOUR,'2018-08-23 10:13:01','2018-09-30 19:38:45') AS DIFF_HOUR, -- 小时
TIMESTAMPDIFF(DAY ,'2018-08-23 10:13:01','2018-09-30 19:38:45') AS DIFF_DATE1, -- 天
DATEDIFF('2018-09-30 19:38:45','2018-08-23 10:13:01') AS DIFF_DATE2, -- 天
TIMESTAMPDIFF(MONTH,'2018-08-23 10:13:01','2018-09-25 19:38:45') AS DIFF_MONTH, -- 月
TIMESTAMPDIFF(YEAR,'2018-08-23 10:13:01','2020-07-25 19:38:45') AS DIFF_YEAR -- 年
FROM DUAL;