Почему запрос гибернации не может быть выполнен без 'Индекс столбца выходит за пределы диапазона: 1, количество столбцов: 0.'? - PullRequest
0 голосов
/ 09 января 2020
 @Modifying
    @Transactional
    @Query(value = "DO $$ " +
            "   BEGIN " +
            "   IF NOT EXISTS ( " +
            "       SELECT * FROM subscriptions AS s " +
            "       WHERE s.client_id = :clientId AND " +
            "       s.status = :status AND " +
            "       s.messenger = :messenger AND " +
            "       s.batch = :batch AND " +
            "       quote_nullable(s.subscription_config ->> 'countryId') = quote_nullable( :countryId ) AND" +
            "       quote_nullable(s.subscription_config ->> 'cityId') = quote_nullable( :cityId ) AND " +
            "       quote_nullable(s.subscription_config ->> 'professionName') = quote_nullable( :professionName ) AND " +
            "       quote_nullable(s.subscription_config ->> 'salaryFrom') = quote_nullable( :salaryFrom ) " +
            "   )  " +
            "   THEN  " +
            "       INSERT INTO subscriptions (client_id, status, messenger, batch, subscription_config) VALUES ( :clientId, :status, :messenger, :batch, to_jsonb(:subscriptionConfig));  " +
            "   END IF;  " +
            "     RETURN; " +
            "END;  " +
            "$$" ,nativeQuery = true)
    void saveSubscription(
            @Param("clientId") Long clientId,
            @Param("status")String status,
            @Param("messenger")String messenger,
            @Param("batch")Integer batch,
            @Param("subscriptionConfig") SubscriptionConfig subscriptionConfig,
            @Param("countryId") Long countryId,
            @Param("cityId") Long cityId,
            @Param("professionName")String professionName,
            @Param("salaryFrom") Integer salaryFrom);

Я пытаюсь выполнить этот запрос, но в результате я выдал исключение:

Caused by: org.hibernate.exception.DataException: could not execute native bulk manipulation query
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:118)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
    at org.hibernate.engine.query.spi.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:117)
    at org.hibernate.internal.SessionImpl.executeNativeUpdate(SessionImpl.java:1593)
    at org.hibernate.query.internal.NativeQueryImpl.doExecuteUpdate(NativeQueryImpl.java:292)
    at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1584)
    at org.springframework.data.jpa.repository.query.JpaQueryExecution$ModifyingExecution.doExecute(JpaQueryExecution.java:263)
    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:605)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
    ... 27 common frames omitted
Caused by: org.postgresql.util.PSQLException: The column index is out of range: 1, number of columns: 0.
    at org.postgresql.core.v3.SimpleParameterList.bind(SimpleParameterList.java:65)
    at org.postgresql.core.v3.SimpleParameterList.setBinaryParameter(SimpleParameterList.java:132)
    at org.postgresql.jdbc.PgPreparedStatement.bindBytes(PgPreparedStatement.java:983)
    at org.postgresql.jdbc.PgPreparedStatement.setLong(PgPreparedStatement.java:279)
    at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setLong(HikariProxyPreparedStatement.java)
    at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$1.doBind(BigIntTypeDescriptor.java:46)
    at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:74)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:276)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:271)
    at org.hibernate.loader.custom.sql.NamedParamBinder.bind(NamedParamBinder.java:34)
    at org.hibernate.engine.query.spi.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:102)
    ... 44 common frames omitted
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...