Null value was assigned to a property of primitive type setter of

mysql写sql时获取的值为null,报错

Caused by: org.springframework.orm.hibernate4.HibernateSystemException: Null value was assigned to a property of primitive type setter of com.ansh.func.pushtask.repairassignment.entity.InsurerSettlementEntity.taotalHourFee; nested exception is org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.ansh.func.pushtask.repairassignment.entity.InsurerSettlementEntity.taotalHourFee
    at org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:216)
    at org.springframework.orm.hibernate4.HibernateExceptionTranslator.convertHibernateAccessException(HibernateExceptionTranslator.java:57)
    at org.springframework.orm.hibernate4.HibernateExceptionTranslator.translateExceptionIfPossible(HibernateExceptionTranslator.java:44)
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
    at com.sun.proxy.$Proxy179.getInsurerSettlementEntityList(Unknown Source)
    at com.ansh.func.pushtask.repairassignment.service.impl.RepairAssignmentServiceImpl.getInsurerSettlementEntityList(RepairAssignmentServiceImpl.java:323)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
    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.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.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
    at com.sun.proxy.$Proxy182.getInsurerSettlementEntityList(Unknown Source)
    at com.ansh.func.pushtask.repairassignment.web.sys.RepairAssignmentController.getTotalStatistics(RepairAssignmentController.java:198)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    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:749)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
    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)
    ... 59 more

解决方法:

https://www.runoob.com/mysql/mysql-func-ifnull.html

使用IFNULL方法

 

    /**获取保险公司结算数统计数据
     * @param settleStartTime
     * @param settleEndTime
     * @param companyName
     * @return
     */
    /* (non-Javadoc)
     * @see com.ansh.func.pushtask.repairassignment.dao.RepairAssignmentDao#getInsurerSettlementEntityList(java.lang.String, java.lang.String, java.lang.String)
     */
    @Override
    public List<InsurerSettlementEntity> getInsurerSettlementEntityList(String settleStartTime, String settleEndTime,
            String companyName,int currentNum, int pageSize,String type) {
        StringBuffer hql = new StringBuffer();
        if(!"2".equals(type)){
             hql = new StringBuffer(" SELECT companyName,SUM(hourFee) AS taotalHourFee,SUM( rescueFee) AS taotalRescueFee,SUM( finalFee) AS taotalFinalFee,SUM(hourFee+rescueFee+finalFee) AS taotalAllFee FROM repair_assignment  ");
        }else{
             hql = new StringBuffer(" SELECT IFNULL(SUM(hourFee),0) AS taotalHourFee, IFNULL(SUM( rescueFee),0) AS taotalRescueFee, IFNULL(SUM( finalFee),0) AS taotalFinalFee, IFNULL(SUM(hourFee+rescueFee+finalFee),0) AS taotalAllFee FROM repair_assignment  ");
        }
        if(BaseUtil.isNotBlank(companyName) || (BaseUtil.isNotBlank(settleStartTime) && BaseUtil.isNotBlank(settleEndTime))){
            hql.append("WHERE 1=1");
        }
        
        if(BaseUtil.isNotBlank(companyName)){
            hql.append(" and companyName=:companyName");
        }
        
        if(BaseUtil.isNotBlank(settleStartTime)){
            hql.append(" and r.settleTime>=:settleStartTime");
        }
        if(BaseUtil.isNotBlank(settleEndTime)){
            hql.append(" and r.settleTime<=:settleEndTime");
        }
            
        if(!"2".equals(type)){
            hql.append(" GROUP BY  companyName");
        }
        
        Query query= this.getSession().createSQLQuery(hql.toString());
        query.setResultTransformer(Transformers.aliasToBean(InsurerSettlementEntity.class));
        if("1".equals(type)){
            query.setFirstResult(currentNum);
            query.setMaxResults(pageSize);
        }

        if(BaseUtil.isNotBlank(companyName)){
            query.setParameter("companyName", companyName);
        }
        if(BaseUtil.isNotBlank(settleStartTime)){
            query.setParameter("settleStartTime", settleStartTime);
        }
        if(BaseUtil.isNotBlank(settleEndTime)){
            query.setParameter("settleEndTime", settleEndTime);
        }
        
        List<InsurerSettlementEntity> list=query.list();
        if(list!=null && list.size()>0){
            return list;
        }
        return null;
    }

 

posted @ 2019-10-27 04:02  何年何月生  阅读(715)  评论(0编辑  收藏  举报