web-dev-qa-db-fra.com

org.hibernate.QueryException: le paramètre positionnel de type JPA n'était pas un ordinal intégral

J'ai la requête JPQL suivante;

@Query(value = "select req_t " +
        "from TransactionRelation tr " +
        "inner join tr.requestTransaction req_t " +
        "inner join req_t.transactionStateHistory req_t_h " +
        "inner join tr.responseTransaction resp_t " +
        "inner join resp_t.transactionStateHistory resp_t_h " +
        "where req_t.id >?1 " +
        "and req_t.receiver.id=?2 and req_t.requestType in ?3" +
        "and NOT EXISTS (select t from resp_t_h t where t.transactionState = 'REPLIED' )" +
        "and EXISTS (select tt from req_t_h tt where tt.transactionState = 'WAITING_PROVIDER' )"
)
List<Transaction> queryTrabsactions(Long transactionId, Long providerId, Collection<RequestType> requestTypes);

Mais cela imprime l'erreur suivante:

Caused by: Java.lang.IllegalArgumentException: Validation failed for query for method public abstract Java.util.List com.finvale.repositories.TransactionRepository.queryTransactions(Java.lang.Long,Java.lang.Long,Java.util.Collection)!
    at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.Java:92) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.SimpleJpaQuery.<init>(SimpleJpaQuery.Java:62) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.Java:72) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromQueryAnnotation(JpaQueryFactory.Java:53) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.Java:144) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.Java:212) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.Java:77) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.Java:436) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.Java:221) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.Java:277) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.Java:263) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.Java:101) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.Java:1687) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1624) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    ... 47 common frames omitted
Caused by: Java.lang.IllegalArgumentException: org.hibernate.QueryException: JPA-style positional param was not an integral ordinal
    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.Java:131) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.Java:155) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.Java:162) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.Java:663) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.Java:23) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62) ~[na:1.8.0_111]
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43) ~[na:1.8.0_111]
    at Java.lang.reflect.Method.invoke(Method.Java:498) ~[na:1.8.0_111]
    at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.Java:347) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at com.Sun.proxy.$Proxy112.createQuery(Unknown Source) ~[na:na]
    at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.Java:86) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
    ... 60 common frames omitted
Caused by: org.hibernate.QueryException: JPA-style positional param was not an integral ordinal
    at org.hibernate.engine.query.spi.ParameterParser.parse(ParameterParser.Java:192) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.engine.query.spi.ParamLocationRecognizer.parseLocations(ParamLocationRecognizer.Java:59) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.engine.query.spi.HQLQueryPlan.buildParameterMetadata(HQLQueryPlan.Java:381) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.Java:134) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.Java:77) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.Java:153) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.Java:546) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.Java:655) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    ... 68 common frames omitted

Quelle est la raison de mon problème?

8
gstackoverflow

Vous n'avez aucun espace entre les lignes

"and req_t.receiver.id=?2 and req_t.requestType in ?3" +
    "and NOT EXISTS

vérifiez également que le paramètre? 3 n'est pas une liste vide

21
StanislavL

C'est arrivé à moi, j'ai eu un '; 'char à la fin de ma requête, copie collée à partir de mon outil de requête de base de données

@Query(value = " DELETE FROM reunion WHERE id = ?1; ", nativeQuery = true)
4
Julien Feniou

Dans mon cas, j'ai dû supprimer les crochets () autour du paramètre dans ma requête personnalisée JPQL.

Faux:

@Query("SELECT u from user u WHERE u.location in (?1)")

Correct:

@Query("SELECT u from user u WHERE u.location in ?1")
0
Willi Mentzel