錯誤: 操做符不存在: integer <> character varying

報錯信息:sql

 

Caused by: org.postgresql.util.PSQLException: 錯誤: 操做符不存在: integer <> character varying
  建議:沒有匹配指定名稱和參數類型的操做符. 您也許須要增長明確的類型轉換.app

 

問題代碼:post

public List<CameraInfo> findWillBeDeletedCamerasByDeviceId(Long deviceId, List<String> channelNos) {
        StringBuilder sb = new StringBuilder("SELECT camera FROM CameraInfo camera WHERE camera.deviceInfo.id=:deviceId");
        sb.append(" and camera.status >= " + DataStatusType.NORMAL.getNumber());
        if(CollectionUtils.isNotEmpty(channelNos)) {
            sb.append(" and camera.channelNo not in(:channelNos)");
        }
        sb.append(" order by camera.channelNo asc");
        Query query = this.getSession().createQuery(sb.toString());
        query.setParameter("deviceId", deviceId);
        query.setParameterList("channelNos", channelNos,new StringType());
        return query.list();
    }ui

 

解決:this

public List<CameraInfo> findWillBeDeletedCamerasByDeviceId(Long deviceId, List<String> channelNos) {
        List<Integer> chanNos = new ArrayList<Integer>();
        for (String channo : channelNos) {
            chanNos.add(Integer.valueOf(channo));
        }

        StringBuilder sb = new StringBuilder("SELECT camera FROM CameraInfo camera WHERE camera.deviceInfo.id=:deviceId");
        sb.append(" and camera.status >= " + DataStatusType.NORMAL.getNumber());
        if(CollectionUtils.isNotEmpty(channelNos)) {
            sb.append(" and camera.channelNo not in(:channelNos)");
        }
        sb.append(" order by camera.channelNo asc");
        Query query = this.getSession().createQuery(sb.toString());
        query.setParameter("deviceId", deviceId);
        query.setParameterList("channelNos", chanNos);
        return query.list();
    }spa

 

緣由:hibernate

CameraInfo 中channelNo 爲integer類型,低版本的hibernate沒法有效進行類型的轉換致使,需匹配正確的對象類型。postgresql

相關文章
相關標籤/搜索