微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何解决类型转换错误运算符不存在:bigint = bytea?

如何解决如何解决类型转换错误运算符不存在:bigint = bytea?

我正在尝试将在Microsoft sql Server上运行良好的Spring Boot应用程序迁移到Postgresql。但是,在清理完查询以匹配PGsql的语法后,我收到一条错误消息:

org.postgresql.util.PsqlException: ERROR: operator does not exist: bytea = integer
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 868

问题是我有40多个控制器,并使用相同的模式对它们进行编码,它们在sql Server上都可以正常工作,但是在向Postgresql迁移时,在40个控制器中,有3个抛出了这个有趣的错误。我将请求作为Long传递给控制器​​,并且数据库中的列也是Longbigint)。所以我不知道这是从哪里来的。我已经做了很多谷歌搜索,但是并没有解决问题。这是我检查过的一些有价值的链接

以下是控制器之一:

    @PostMapping("/date-sum")
    public ResponseEntity<Object> sumRecordsWithDate(@RequestBody SearcherDto searcherDto) {

        Long type = searcherDto.getCompanyTypeId();
        Long process = searcherDto.getProcesstypeFk();
        Long process1 = searcherDto.getProcesstypeFk1();
        Long process2 = searcherDto.getProcesstypeFk2();
        Long process3 = searcherDto.getProcesstypeFk3();
        LocalDateTime start = LocalDateTime.of(LocalDate.from(searcherDto.getStartDate()),LocalTime.of(0,0));
        LocalDateTime end = LocalDateTime.of(LocalDate.from(searcherDto.getEndDate()),LocalTime.of(23,59,59));


        SumInterface sumInterface = sumRepository
                .sumWithDate(process,process1,process2,process3,type,start,end);

        return ResponseEntity.ok(new JsonResponse("See Data Object for Details",sumInterface));
    }

这是我从邮递员那里发送的请求:

{
"startDate": "2014-06-11","endDate": "2020-10-14","processtypeFk":9542,"companyTypeId": 6995

    }

下面是我的本地查询存储库:

    @Query(value = "SELECT sum(case when (IS_QUERIED = false AND SUBMITTED = true) then b.AMOUNT else null end) AS pending," +
            " sum(case when (SUBMITTED = false OR SUBMITTED IS NULL) then b.AMOUNT else null end) AS notSubmitted," +
            " sum(case when ( (SUBMITTED = true)) then 1 else null end) AS submitted," +
            " sum(b.AMOUNT) AS totalApplications," +
            " sum(case when (IS_QUERIED = true ) then b.AMOUNT else null end) AS queried," +
            " sum(case when (APPROVED = true) then b.AMOUNT else null end) AS approved," +
            " sum(case when (APPROVED = false) then b.AMOUNT else null end) AS notApproved " +
            " FROM ANNUAL_RETURNS a" +
            " LEFT JOIN PAYMENT_HISTORY b ON a.id=b.RECORD_ID AND b.PROCESS_TYPE_FK = a.PROCESS_TYPE_FK"+
            " LEFT JOIN COMPANY c ON c.id= a.COMPANY_FK " +
            " WHERE (a.FINANCIAL_YEAR_END >=:startDate AND a.FINANCIAL_YEAR_END <=:endDate) AND " +
            " b.PAYMENT_STATUS='APPROVED' AND (c.COMPANY_TYPE_FK=:companyTypeId OR :companyTypeId=0) " +
            " AND (a.PROCESS_TYPE_FK =:processtypeFk OR " +
            "(:processtypeFk1=9542 AND :processtypeFk2=9594 AND :processtypeFk3=9598)) ",nativeQuery = true)
    SumInterface sumWithDate(@Param("processtypeFk")Long processtypeFk,@Param("processtypeFk1")Long processtypeFk1,@Param("processtypeFk2") Long processtypeFk2,@Param("processtypeFk3") Long processtypeFk3,@Param("companyTypeId") Long companyTypeId,@Param("startDate") LocalDateTime startDate,@Param("endDate") LocalDateTime endDate);

更新:

这里是另一个没有传递LocalDateTime参数的控制器,该控制器抛出相同的错误

    @PostMapping("/count")
    public ResponseEntity<Object> countRecords(@RequestBody SearcherDto searcherDto) {

        Long type = searcherDto.getCompanyTypeId();
        Long process = searcherDto.getProcesstypeFk();
        Long process1 = searcherDto.getProcesstypeFk1();
        Long process2 = searcherDto.getProcesstypeFk2();
        Long process3 = searcherDto.getProcesstypeFk3();
        SumInterface annualReturnInterface = sumRepository
                .countReturns(process,type);

        return ResponseEntity.ok(new JsonResponse("See Data Object for Details",sumInterface));
    }

//the corresponding repository with native query is

    @Query(value = "SELECT count(case when (IS_QUERIED = false AND SUBMITTED = true) then 1 else null end) AS pending," +
            " count(case when (SUBMITTED = false OR SUBMITTED IS NULL) then 1 else null end) AS notSubmitted," +
            " count(case when ( (SUBMITTED = true)) then 1 else null end) AS submitted," +
            " count(*) AS totalApplications," +
            " count(case when (IS_QUERIED = true) then 1 else null end) AS queried," +
            " count(case when (APPROVED = true) then 1 else null end) AS approved," +
            " count(case when (APPROVED = false) then 1 else null end) AS notApproved " +
            " FROM ANNUAL_RETURNS a" +
            " LEFT JOIN PAYMENT_HISTORY b ON a.id=b.RECORD_ID AND b.PROCESS_TYPE_FK = a.PROCESS_TYPE_FK" +
            " LEFT JOIN COMPANY c ON c.id= a.COMPANY_FK " +
            " WHERE (c.COMPANY_TYPE_FK=:companyTypeId OR :companyTypeId=0) AND (a.PROCESS_TYPE_FK =:processtypeFk OR " +
            "(:processtypeFk1=9542 AND :processtypeFk2=9594 AND :processtypeFk3=9598)) ",nativeQuery = true)
    AnnualReturnInterface countReturn(@Param("processtypeFk") Long processtypeFk,@Param("processtypeFk1") Long processtypeFk1,@Param("companyTypeId") Long companyTypeId);


以下是使用邮递员为此控制器发送的请求:

{

"processtypeFk1": 9542,"processtypeFk2": 9598,"processtypeFk3": 9594,"companyTypeId": 0

       }

以下是我向两个控制器发出请求时得到的错误跟踪:

org.postgresql.util.PsqlException: ERROR: operator does not exist: bytea = integer
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 868
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553) ~[postgresql-42.2.16.jar:42.2.16]
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285) ~[postgresql-42.2.16.jar:42.2.16]
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323) ~[postgresql-42.2.16.jar:42.2.16]
    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:473) ~[postgresql-42.2.16.jar:42.2.16]
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:393) ~[postgresql-42.2.16.jar:42.2.16]
    at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164) ~[postgresql-42.2.16.jar:42.2.16]
    at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:114) ~[postgresql-42.2.16.jar:42.2.16]
    at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) ~[HikariCP-3.4.5.jar:na]
    at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java) ~[HikariCP-3.4.5.jar:na]
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.loader.Loader.getResultSet(Loader.java:2341) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2094) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2056) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.loader.Loader.doQuery(Loader.java:953) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:350) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.loader.Loader.doList(Loader.java:2887) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.loader.Loader.doList(Loader.java:2869) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2701) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.loader.Loader.list(Loader.java:2696) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.loader.custom.Customloader.list(Customloader.java:338) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:2142) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1163) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:173) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1533) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.query.internal.AbstractProducedQuery.getSingleResult(AbstractProducedQuery.java:1581) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:196) ~[spring-data-jpa-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:88) ~[spring-data-jpa-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:154) ~[spring-data-jpa-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:142) ~[spring-data-jpa-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor$QueryMethodInvoker.invoke(QueryExecutorMethodInterceptor.java:195) ~[spring-data-commons-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:152) ~[spring-data-commons-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:130) ~[spring-data-commons-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80) ~[spring-data-commons-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:149) ~[spring-data-jpa-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at com.sun.proxy.$Proxy178.sumAnnualReturnByProcesstypeAndOrCompanyTypeWithDate(UnkNown Source) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:205) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at com.sun.proxy.$Proxy90.sumAnnualReturnByProcesstypeAndOrCompanyTypeWithDate(UnkNown Source) ~[na:na]
    at com.oasis.isds.executivedashboard.controller.AnnualReturnController.sumAnnualReturnRecordsWithDate(AnnualReturnController.java:94) ~[classes/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
    at org.springframework.web.method.support.invocableHandlerMethod.doInvoke(invocableHandlerMethod.java:190) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.web.method.support.invocableHandlerMethod.invokeForRequest(invocableHandlerMethod.java:138) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletinvocableHandlerMethod.invokeAndHandle(ServletinvocableHandlerMethod.java:105) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.web.servlet.dispatcherServlet.dodispatch(dispatcherServlet.java:1040) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.web.servlet.dispatcherServlet.doService(dispatcherServlet.java:943) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:652) ~[tomcat-embed-core-9.0.38.jar:4.0.FR]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.38.jar:4.0.FR]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.38.jar:9.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:113) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:118) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:158) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at com.oasis.isds.executivedashboard.security.JwtAuthTokenFilter.doFilterInternal(JwtAuthTokenFilter.java:49) ~[classes/:na]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.authentication.logout.logoutFilter.doFilter(logoutFilter.java:116) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:92) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:92) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:77) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178) ~[spring-security-web-5.3.4.RELEASE.jar:5.3.4.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.tomcat.util.net.socketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]

这是两个主要实体

//first entity

@Entity
@Table(name="ANNUAL_RETURNS")
public class AnnualReturn implements Serializable {

    private static final long serialVersionUID = 1L;


    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Long id;

    @Column(name = "IS_QUERIED")
    private Boolean queried;

    @Column(name = "FINANCIAL_YEAR_END")
    private String financialYearEnd;
    @Column(name = "FINANCIAL_YEAR_START")
    private String financialYearStart;

    @Column(name = "FINANCIAL_YEAR")
    private String financialYear;

    private Boolean approved;

    @Column(name = "APPRoval_DATE")
    private Date approvalDate;

    @ManyToOne
    @JoinColumn(name = "COMPANY_FK")
    private Company company;

    @ManyToOne
    @JoinColumn(name = "PROCESS_TYPE_FK",referencedColumnName = "id")
    private Process_Type processtype;

}

//second entity


@Data
@Entity
@Table(name = "COMPANY")
@JsonIgnoreProperties({"hibernateLazyInitializer","handler"})
public class Company implements Serializable {

    private static final long serialVersionUID = -4358934782506546691L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Long id;

    @Column(name = "APPROVED_NAME")
    private String approvedname;

    @Column(name = "REGISTRATION_APPROVED")
    private Boolean registrationApproved;

    @Column(name = "RC_NUMBER")
    private String rcNumber;

    @Column(name = "ADDRESS")
    private String address;

    @JsonIgnore
    @OnetoOne
    @JoinColumn(name = "COMPANY_TYPE_FK",referencedColumnName = "id")
    private Company_Type companyTypeFk;

    @Column(name = "DATE_OF_APPRoval")
    private Date dateOfApproval;




请帮助我提供想法和可能的解决方案。

解决方法

  1. 在每个要修复的属性中使用@Convert,

  2. 将自定义类传递给 @Convert(converter = CustomConverter.class)

  3. 比CustomConverter应该实现javax的AttributeConverter

  4. 编写您的自定义逻辑。

,

最有可能是bytea。您的驱动程序不知道如何处理,可能正在使用默认的Java序列化将其转换为bigint(与long startValue = start.atOffset(ZoneOffset.UTC).toEpochSecond(); 相比)。

最简单的解决方案(因为您已经在使用本地查询而不是JPA)是自己转换。只有您知道应该怎么做(一个纪元时间?秒或毫秒?什么时区?),但是类似:

OffsetDateTime

更高级的配置将涉及注册正确的转换器。再一次,将不会有一个开箱即用的方法,因为没有从本地日期时间获取整数的定义方法。

我建议您改用完全指定的类型(ZonedDateTimeInstant,{{1}}),并在架构中使用正确的日期时间类型。

,

对此有一个解决方法,但是除非PostgreSQL团队决定在解析器中为在初始执行时传递null的时候创建一个延迟的类型检查,否则它没有实际的解决方法。

因此,解决方法是...

private static final Long LONG_CONST = 0L;
@PostMapping("/date-sum")
public ResponseEntity<Object> sumRecordsWithDate(@RequestBody SearcherDto searcherDto) {

    Long type = searcherDto.getCompanyTypeId();
    Long process = searcherDto.getProcessTypeFk();
    Long process1 = searcherDto.getProcessTypeFk1();
    Long process2 = searcherDto.getProcessTypeFk2();
    Long process3 = searcherDto.getProcessTypeFk3();
    LocalDateTime start = LocalDateTime.of(LocalDate.from(searcherDto.getStartDate()),LocalTime.of(0,0));
    LocalDateTime end = LocalDateTime.of(LocalDate.from(searcherDto.getEndDate()),LocalTime.of(23,59,59));

    // difference starts here
    EntityManager em = getEntityManager();

    Query q = em.createNativeQuery(...,ReturnType.class);
    // or createNamedQuery if you've registered it via NamedNativeQuery,which I recommend
    q.setParameter("processTypeFk",LONG_CONST).setParameter("processTypeFk",process);
    q.setParameter("processTypeFk1",LONG_CONST).setParameter("processTypeFk1",process1);
    q.setParameter("processTypeFk2",LONG_CONST).setParameter("processTypeFk2",process2);
    q.setParameter("processTypeFk3",LONG_CONST).setParameter("processTypeFk3",process3);
    q.setParameter("companyTypeId",LONG_CONST).setParameter("companyTypeId",companyTypeId)
    // these are never null,so we don't need to type-set them.
    q.setParameter("startDate",start);
    q.setParameter("endDate",end);

    ... q.getResultList();

    return ResponseEntity.ok(new JsonResponse("See Data Object for Details",sumInterface));
}

这是在第一次调用setParameter时发生的情况,您正在使用非null值来确保Hibernate正确地确定了该参数的类型,然后在第二次调用中您设置了正确的值(并且值(可能为null),但是类型检查已经完成,因此将被跳过。

,

经过几天的头脑风暴,我得以解决此问题。我发现PostgreSQL驱动程序无法处理参数中的所有抽象。它看到一些为空。因此,在尝试了不同的建议之后,对我没有任何帮助的是,我重新设计了代码,并创建了新的端点来处理其他抽象级别。

简而言之,我减少了存储库和控制器方法的重载,以避免传递空值,因为MS SQL可以处理,但是postgreSQL无法处理。

这是我新的存储库接口方法:

    @Query(value = "SELECT count(case when (IS_QUERIED = false AND SUBMITTED = true) 
then 1 else null end) AS pending,count(case when (SUBMITTED = false OR SUBMITTED IS NULL) then 1 else null end) AS notSubmitted,count(case when ( (SUBMITTED = true)) then 1 else null end) AS submitted,count(*) AS totalApplications,count(case when (IS_QUERIED = true) then 1 else null end) AS queried,count(case when (APPROVED = true) then 1 else null end) AS approved,count(case when (APPROVED = false) then 1 else null end) AS notApproved 
FROM ANNUAL_RETURNS a LEFT JOIN PAYMENT_HISTORY b ON a.id=b.RECORD_ID 
AND b.PROCESS_TYPE_FK = a.PROCESS_TYPE_FK LEFT JOIN COMPANY c 
ON c.id= a.COMPANY_FK WHERE (c.COMPANY_TYPE_FK=:companyTypeId OR :companyTypeId=0) 
AND a.PROCESS_TYPE_FK =:processTypeFk ",nativeQuery = true)
AnnualReturnInterface countReturn(@Param("processTypeFk") Long processTypeFk,@Param("companyTypeId") Long companyTypeId);

这是新的控制器方法:

@PostMapping("/count")
    public ResponseEntity<Object> countAnnualReturnRecordsByOneProcessType
(@RequestBody SearcherDto searcherDto) {

        Long companyType = searcherDto.getCompanyTypeId();
        Long processType = searcherDto.getProcessTypeFk();

        AnnualReturnInterface annualReturnInterface = annualReturnRepository
                .countAnnualReturnByOneProcessTypeAndCompanyType(processType,companyType);

        return ResponseEntity.ok(new JsonResponse("See Data Object for Details",annualReturnInterface));
    }

这是第二种新的存储库接口方法:(注意:这两个查询是从问题中的一个中拉出的。)

    @Query(value = "SELECT count(case when (IS_QUERIED = false AND SUBMITTED = true) 
then 1 else null end) AS pending,count(case when (SUBMITTED = false OR SUBMITTED IS NULL)
 then 1 else null end) AS notSubmitted,count(case when ( (SUBMITTED = true)) then 1 
else null end) AS submitted,count(case when (APPROVED = false) then 1 else null end) AS notApproved  
FROM ANNUAL_RETURNS a LEFT JOIN PAYMENT_HISTORY b ON a.id=b.RECORD_ID 
AND b.PROCESS_TYPE_FK = a.PROCESS_TYPE_FK LEFT JOIN COMPANY c ON 
c.id= a.COMPANY_FK WHERE (c.COMPANY_TYPE_FK=:companyTypeId OR :companyTypeId=0) AND a.PROCESS_TYPE_FK in (9542,9594,9598) ",nativeQuery = true)

    AnnualReturnInterface countAnnualReturnByAllProcessTypeAndOrCompanyType(@Param("companyTypeId") Long companyTypeId);
    }

第二个控制器如下:

@PostMapping("/count-all")
    public ResponseEntity<Object> countAnnualReturnRecordsByAllProcessType
(@RequestBody SearcherDto searcherDto) {

        Long companyType = searcherDto.getCompanyTypeId();
        AnnualReturnInterface annualReturnInterface = annualReturnRepository
                .countAnnualReturnByAllProcessTypeAndOrCompanyType(companyType);

        return ResponseEntity.ok(new JsonResponse("See Data Object for Details",annualReturnInterface));
    }

到目前为止,我的代码现在可以在postgreSQL上运行,但是与MS SQL相比设计有所不同。

感谢所有提出问题的人。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。