我有一个存储库:
@Query(value = "SELECT DISTINCT ci_id, ci_name, ci_area, ci_insee_code, ci_zip_code " +
"FROM city " +
"LEFT JOIN area ON ar_group_id IN (:groups) " +
"WHERE ci_name LIKE CONCAT('%',UPPER(:name),'%') " +
"AND ST_INTERSECTS(ar_polygon, ci_area)", nativeQuery = true)
Page<City> findByNameAndGroups(@Param("name") String name, @Param("groups") List<Long> groups, Pageable pageable);
当我使用 name ='ab'和 groups = [52] 调用此方法时,它可以工作。
但是如果我使用 name ='a'和 groups = [52] 进行呼叫,则会遇到下一个错误:
java.sql.SQLException:您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以获取正确的语法,以在')处使用正确的语法从ar_group_id IN(52)所在城市的LEFT JOIN区域开始在第1行的ci_name LIKE CONCAT('%',' 查询是:从ar_group_id IN(?)上的城市左联接区域选择count(DISTINCT LEFT),在哪里ci_name LIKE CONCAT('%',UPPER(?),'%')和ST_INTERSECTS(ar_polygon,ci_area),参数[52, '一种'] 在org.mariadb.jdbc.internal.util.LogQueryTool.exceptionWithQuery(LogQueryTool.java:153) 在org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:254) 在org.mariadb.jdbc.MariaDbPreparedStatementClient.executeInternal(MariaDbPreparedStatementClient.java:209) 在org.mariadb.jdbc.MariaDbPreparedStatementClient.execute(MariaDbPreparedStatementClient.java:150) 在org.mariadb.jdbc.MariaDbPreparedStatementClient.executeQuery(MariaDbPreparedStatementClient.java:164) 在com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) 在com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java) 在org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60) 在org.hibernate.loader.Loader.getResultSet(Loader.java:2168) 在org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1931) 在org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1893) 在org.hibernate.loader.Loader.doQuery(Loader.java:938) 在org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341) 在org.hibernate.loader.Loader.doList(Loader.java:2692) 在org.hibernate.loader.Loader.doList(Loader.java:2675) 在org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2507) 在org.hibernate.loader.Loader.list(Loader.java:2502) 在org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:335) 在org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:2161) 在org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1016) 在org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:152) 在org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414) 在org.hibernate.query.Query.getResultList(Query.java:146) 在org.springframework.data.jpa.repository.query.JpaQueryExecution $ PagedExecution.count(JpaQueryExecution.java:201) 在org.springframework.data.jpa.repository.query.JpaQueryExecution $ PagedExecution.lambda $ doExecute $ 0(JpaQueryExecution.java:195)处 在org.springframework.data.repository.support.PageableExecutionUtils.getPage(PageableExecutionUtils.java:62) 在org.springframework.data.jpa.repository.query.JpaQueryExecution $ PagedExecution.doExecute(JpaQueryExecution.java:194) 在org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:91)处 在org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:136) 在org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:125) 在org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:590) 在org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:578) 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 在org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 在org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) 在org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 在org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 在org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor $ CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135)处 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 在org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 在org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 在org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) 在com.sun.proxy。$ Proxy147.findByNameAndGroups(未知来源) 在com.francetaxi.hub.controller.CityController.search(CityController.java:35) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498) 在org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) 在org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) 在org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) 在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870) 在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776) 在org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) 在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) 在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) 在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) 在org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:635) 在org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:742) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.springframework.web.filter.AbstractRequestLoggingFilter.doFilterInternal(AbstractRequestLoggingFilter.java:245) 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.springframework.web.filter.AbstractRequestLoggingFilter.doFilterInternal(AbstractRequestLoggingFilter.java:245) 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) 在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) 在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) 在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) 在org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) 在org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) 在org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:790) 在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1459) 在org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) 在org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) 在java.lang.Thread.run(Thread.java:748)
感谢您的帮助