title: Spring data JPA PSQLException using @Query and @Modifying
body: <p>Using spring-boot-starter-data-jpa (Version 2.0.4.RELEASE) and PostgreSQL (Version 9.5.10), I keep getting the <strong>PSQLException</strong>: No results were returned by the query, though I did use <code>@Modifying</code> as proposed by many others here. Adding <code>@Transactional</code> as suggested by some, didn't make a difference either.
  Analyzing the StackTrace one could see that <code>org.postgresql.jdbc.PgPreparedStatement.executeQuery()</code> is called, whereas <code>org.postgresql.jdbc.PgPreparedStatement.executeUpdate()</code> should be called. 
  What can I do?</p>
  
  <pre><code>@Repository
  public interface Rank extends JpaRepository&lt;RankArticle, String&gt; {
  
  @Modifying
  @Query(value = "UPDATE rank SET id=calc.id, shop_id=calc.shop_id, " +
                  "score=calc.score, rank = calc.rank FROM " +
                      "(SELECT id, shop_id, SUM(sales) AS score, CAST(NULL AS INT) AS rank " +
                      "FROM " +
                          "(SELECT id, sales, shop_id FROM daily_pod " +
                          "WHERE shop_id = :shopId " +
                          "UNION " +
                          "SELECT id, sales, shop_id FROM weekly_pod " +
                          "WHERE shop_id = :shopId " +
                          "UNION " +
                          "SELECT id, sales, shop_id FROM end_pod " +
                          "WHERE shop_id = :shopId) " +
                      "AS pods " +
                      "GROUP BY id, shop_id ORDER BY score DESC limit :limit) as calc;"
          , nativeQuery = true)
  void calcScore(@Param("shopId") Integer shopId,
                 @Param("limit") Integer limit);
  </code></pre>
  
  <p>}</p>
  
  <blockquote>
    <p>EDIT: Add Full Stack-Trace:</p>
  
  <pre><code>[ERROR] 2018-09-20 17:49:10,503 [SimpleAsyncTaskExecutor-1] [d.t.p.v.backend.VerkaufsrangConfig] - Konnte AMQP-Nachricht nicht
  </code></pre>
    
    <p>verarbeiten!
          org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException:
    Listener method 'public void
    de.thalia.pim.verkaufsrang.backend.application.rabbitmq.SalesHandler.receive(org.springframework.amqp.core.Message)'
    threw exception
           at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:190)
           at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:120)
               at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1414)
                 at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1337)
               at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1324)
           at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1303)
              at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:817)
              at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:801)
                at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$700(SimpleMessageListenerContainer.java:77)
              at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1042)
              at java.base/java.lang.Thread.run(Thread.java:844)
          Caused by: org.springframework.orm.jpa.JpaSystemException: could not extract ResultSet; nested exception is
    org.hibernate.exception.GenericJDBCException: could not extract
    ResultSet
              at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:314)
              at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:225)
             at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:527)
                 at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
                at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
              at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
           at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135)
             at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
            at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
                 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
                at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
                at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
               at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
               at com.sun.proxy.$Proxy123.calcScore(Unknown Source)
                at de.thalia.pim.verkaufsrang.backend.business.SalesRankService.calculateRank(SalesRankService.java:28)
            at de.thalia.pim.verkaufsrang.backend.application.rabbitmq.SalesHandler.receive(SalesHandler.java:60)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
    Method)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
              at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.base/java.lang.reflect.Method.invoke(Method.java:564)
            at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:181)
           at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:114)
            at org.springframework.amqp.rabbit.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:51)
              at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:182)
              ... 10 common frames omitted
          Caused by: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
           at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
              at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
                 at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
             at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:69)
              at org.hibernate.loader.Loader.getResultSet(Loader.java:2168)
                at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1931)
             at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1893)
              at org.hibernate.loader.Loader.doQuery(Loader.java:938)
              at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
           at org.hibernate.loader.Loader.doList(Loader.java:2692)
               at org.hibernate.loader.Loader.doList(Loader.java:2675)
           at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2507)
                 at org.hibernate.loader.Loader.list(Loader.java:2502)
               at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:335)
           at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:2200)
              at org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1016)
                at org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:152)
           at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414)
           at org.hibernate.query.Query.getResultList(Query.java:146)
            at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
    Method)
                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.base/java.lang.reflect.Method.invoke(Method.java:564)
              at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:380)
             at com.sun.proxy.$Proxy141.getResultList(Unknown Source)
              at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:129)
                 at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:91)
               at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:136)
            at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:125)
           at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:590)
               at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:578)
             at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
            at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
           at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
              at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
           at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
              at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
                 at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
           ... 29 common frames omitted
          Caused by: org.postgresql.util.PSQLException: No results were returned by the query.
              at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:114)
            at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
              at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
               at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60)
            ... 63 common frames omitted</p>
  </blockquote>