Announcement Announcement Module
Collapse
No announcement yet.
DataNucleus - query doesnt make use of this parameter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • DataNucleus - query doesnt make use of this parameter

    Hi,

    I have project using spring-data-jpa 1.5.1 + eclipselink(JPA 2.1) 2.5.1 + PostgreSQL 8.4. All my tests work with this setup.
    For two days now I'm trying DataNucleus-jpa. We have two issues with DataNucleus 4.0.0-m3:
    1-Strange error with tables not existing (like this one http://stackoverflow.com/questions/1...s-not-existing)

    This I've fixed it with the following property: datanucleus.identifier.case

    The second one I've not resolved yet:
    Code:
    09:17:34.223 [main] DEBUG DataNucleus.Datastore.Schema - Column info loaded for Catalog "", Schema "sapeo", 3 tables, time = 26 ms
    09:17:34.223 [main] DEBUG DataNucleus.Datastore.Schema - Column info retrieved for table "ato_legal" : 8 columns found
    09:17:34.226 [main] DEBUG DataNucleus.Datastore.Schema - Check of existence of sapeo.ato_legal_tipo returned table type of TABLE
    09:17:34.230 [main] DEBUG DataNucleus.Datastore.Schema - Check of existence of sapeo.veiculo_publicacao returned table type of TABLE
    09:17:34.230 [main] DEBUG DataNucleus.Datastore.Schema - Schema Transaction committing with connection "org.a[email protected]6f2c94cc"
    09:17:34.231 [main] DEBUG DataNucleus.Datastore.Schema - Schema Transaction closing with connection "org.a[email protected]6f2c94cc"
    09:17:34.234 [main] DEBUG DataNucleus.Datastore.Native - SELECT relname FROM pg_class WHERE relname=? : for sequence=veiculo_publicacao_id_seq
    09:17:34.237 [main] DEBUG DataNucleus.Datastore - Closing PreparedStatement "[email protected]"
    09:17:34.238 [main] DEBUG DataNucleus.Datastore.Native - SELECT nextval('sapeo.veiculo_publicacao_id_seq')
    09:17:34.239 [main] DEBUG DataNucleus.Datastore.Retrieve - Execution Time = 1 ms
    09:17:34.239 [main] DEBUG DataNucleus.Datastore - Closing PreparedStatement "[email protected]2c"
    09:17:34.272 [main] DEBUG DataNucleus.Query - JPQL Single-String with "select b from VeiculoPublicacao b where b.nuPublicacao = :nuPublicacao and b.tipo = :tipo"
    09:17:34.273 [main] DEBUG DataNucleus.Query - JPQL Query : Compiling "SELECT b FROM VeiculoPublicacao b WHERE b.nuPublicacao = :nuPublicacao and b.tipo = :tipo"
    09:17:34.290 [main] DEBUG DataNucleus.Query - JPQL Query : Compile Time = 16 ms
    09:17:34.290 [main] DEBUG DataNucleus.Query - QueryCompilation:
      [from:ClassExpression(alias=b)]
      [filter:DyadicExpression{DyadicExpression{PrimaryExpression{b.nuPublicacao}  =  ParameterExpression{nuPublicacao}}  AND  DyadicExpression{PrimaryExpression{b.tipo}  =  ParameterExpression{tipo}}}]
      [symbols: b type=br.gov.to.secad.sapeo.model.VeiculoPublicacao, tipo type=br.gov.to.secad.sapeo.model.VeiculoPublicacaoTipoEnum, nuPublicacao type=java.lang.String]
    Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 3.903 sec <<< FAILURE! - in br.gov.to.secad.sapeo.repository.VeiculoPublicacaoRepositoryTest
    savesAndFindsVeiculoPublicacaoByNuVeiculoPublicacaoAndTipo(br.gov.to.secad.sapeo.repository.VeiculoPublicacaoRepositoryTest)  Time elapsed: 3.632 sec  <<< ERROR!
    org.springframework.dao.InvalidDataAccessApiUsageException: Query has parameter "1" supplied at execution yet the query doesnt make use of this parameter; nested exception is java.lang.IllegalArgumentException: Query has parameter "1" supplied at execution yet the query doesnt make use of this parameter
            at org.datanucleus.store.query.Query.applyImplicitParameterValueToCompilation(Query.java:921)
            at org.datanucleus.store.query.AbstractJPQLQuery.compileInternal(AbstractJPQLQuery.java:315)
            at org.datanucleus.store.rdbms.query.JPQLQuery.compileInternal(JPQLQuery.java:230)
            at org.datanucleus.store.query.Query.setImplicitParameter(Query.java:839)
            at org.datanucleus.store.rdbms.query.JPQLQuery.setImplicitParameter(JPQLQuery.java:162)
            at org.datanucleus.api.jpa.JPAQuery.setParameter(JPAQuery.java:509)
            at org.datanucleus.api.jpa.JPAQuery.setParameter(JPAQuery.java:58)
            at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:133)
            at org.springframework.data.jpa.repository.query.StringQueryParameterBinder.bind(StringQueryParameterBinder.java:61)
            at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:110)
            at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:153)
            at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:144)
            at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.doCreateQuery(AbstractStringBasedJpaQuery.java:68)
            at org.springframework.data.jpa.repository.query.AbstractJpaQuery.createQuery(AbstractJpaQuery.java:145)
            at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:142)
            at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:61)
            at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:96)
            at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:86)
            at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:337)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
            at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
            at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
            at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
            at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
            at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:92)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
            at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
            at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
            at com.sun.proxy.$Proxy47.findOneByNuPublicacaoAndTipo(Unknown Source)
            at br.gov.to.secad.sapeo.repository.VeiculoPublicacaoRepositoryTest.savesAndFindsVeiculoPublicacaoByNuVeiculoPublicacaoAndTipo(VeiculoPublicacaoRepositoryTest.java:52)
    The spring-data-jpa repository:

    Code:
    @Repository
    public interface IVeiculoPublicacaoRepository extends JpaRepository<VeiculoPublicacao, Long> {
        @Query("select b from VeiculoPublicacao b where b.nuPublicacao = :nuPublicacao and b.tipo = :tipo")
        public VeiculoPublicacao findOneByNuPublicacaoAndTipo(@Param("nuPublicacao") String nuPublicacao, @Param("tipo") VeiculoPublicacaoTipoEnum tipo);
    }
    Executing the same query directly on Entity Manager works perfectly:
    Code:
           veiculoPublicacao = new VeiculoPublicacao();
            veiculoPublicacao.setTipo(VeiculoPublicacaoTipoEnum.DOE);
            veiculoPublicacao.setNuPublicacao("444");
            veiculoPublicacao.setDtPublicacao(new Date());
    
            entityManager.persist(veiculoPublicacao);
          
            TypedQuery<VeiculoPublicacao> q = entityManager.createQuery("select b from VeiculoPublicacao b where b.nuPublicacao = :nuPublicacao and b.tipo = :tipo", VeiculoPublicacao.class);
            q.setParameter("nuPublicacao", "444");
            q.setParameter("tipo", VeiculoPublicacaoTipoEnum.DOE);
            VeiculoPublicacao singleResult = q.getSingleResult();
            Assert.assertThat(singleResult, is(veiculoPublicacao));
    Would you mind help me on the last one?

    Regards,

    Gilberto
    Last edited by gilbertoca; May 27th, 2014, 08:21 AM.

  • #2
    Try this...
    Code:
     @Query("select b from VeiculoPublicacao b where b.nuPublicacao = ?1 and b.tipo = ?2")    
     public VeiculoPublicacao findOneByNuPublicacaoAndTipo(String nuPublicacao, String tipo);

    Comment


    • #3
      Have you seen the exception? It says:
      Query has parameter "1" supplied at execution yet the query doesnt make use of this parameter;
      How come the Query has only one parameter? It has two!!

      Comment


      • #4
        Hi, Andy.

        I've tried to debug the Query but come just to the point of the compilation:
        Code:
        09:17:34.223 [main] DEBUG DataNucleus.Datastore.Schema - Column info loaded for Catalog "", Schema "sapeo", 3 tables, time = 26 ms
        09:17:34.223 [main] DEBUG DataNucleus.Datastore.Schema - Column info retrieved for table "ato_legal" : 8 columns found
        09:17:34.226 [main] DEBUG DataNucleus.Datastore.Schema - Check of existence of sapeo.ato_legal_tipo returned table type of TABLE
        09:17:34.230 [main] DEBUG DataNucleus.Datastore.Schema - Check of existence of sapeo.veiculo_publicacao returned table type of TABLE
        09:17:34.230 [main] DEBUG DataNucleus.Datastore.Schema - Schema Transaction committing with connection "org.a[email protected]6f2c94cc"
        09:17:34.231 [main] DEBUG DataNucleus.Datastore.Schema - Schema Transaction closing with connection "org.a[email protected]6f2c94cc"
        09:17:34.234 [main] DEBUG DataNucleus.Datastore.Native - SELECT relname FROM pg_class WHERE relname=? : for sequence=veiculo_publicacao_id_seq
        09:17:34.237 [main] DEBUG DataNucleus.Datastore - Closing PreparedStatement "[email protected]"
        09:17:34.238 [main] DEBUG DataNucleus.Datastore.Native - SELECT nextval('sapeo.veiculo_publicacao_id_seq')
        09:17:34.239 [main] DEBUG DataNucleus.Datastore.Retrieve - Execution Time = 1 ms
        09:17:34.239 [main] DEBUG DataNucleus.Datastore - Closing PreparedStatement "[email protected]2c"
        09:17:34.272 [main] DEBUG DataNucleus.Query - JPQL Single-String with "select b from VeiculoPublicacao b where b.nuPublicacao = :nuPublicacao and b.tipo = :tipo"
        09:17:34.273 [main] DEBUG DataNucleus.Query - JPQL Query : Compiling "SELECT b FROM VeiculoPublicacao b WHERE b.nuPublicacao = :nuPublicacao and b.tipo = :tipo"
        09:17:34.290 [main] DEBUG DataNucleus.Query - JPQL Query : Compile Time = 16 ms
        09:17:34.290 [main] DEBUG DataNucleus.Query - QueryCompilation:
          [from:ClassExpression(alias=b)]
          [filter:DyadicExpression{DyadicExpression{PrimaryExpression{b.nuPublicacao}  =  ParameterExpression{nuPublicacao}}  AND  DyadicExpression{PrimaryExpression{b.tipo}  =  ParameterExpression{tipo}}}]
          [symbols: b type=br.gov.to.secad.sapeo.model.VeiculoPublicacao, tipo type=br.gov.to.secad.sapeo.model.VeiculoPublicacaoTipoEnum, nuPublicacao type=java.lang.String]
        Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 3.903 sec <<< FAILURE! - in br.gov.to.secad.sapeo.repository.VeiculoPublicacaoRepositoryTest
        savesAndFindsVeiculoPublicacaoByNuVeiculoPublicacaoAndTipo(br.gov.to.secad.sapeo.repository.VeiculoPublicacaoRepositoryTest)  Time elapsed: 3.632 sec  <<< ERROR!
        org.springframework.dao.InvalidDataAccessApiUsageException: Query has parameter "1" supplied at execution yet the query doesnt make use of this parameter; nested exception is java.lang.IllegalArgumentException: Query has parameter "1" supplied at execution yet the query doesnt make use of this parameter
                at org.datanucleus.store.query.Query.applyImplicitParameterValueToCompilation(Query.java:921)
                at org.datanucleus.store.query.AbstractJPQLQuery.compileInternal(AbstractJPQLQuery.java:315)
                at org.datanucleus.store.rdbms.query.JPQLQuery.compileInternal(JPQLQuery.java:230)
                at org.datanucleus.store.query.Query.setImplicitParameter(Query.java:839)
                at org.datanucleus.store.rdbms.query.JPQLQuery.setImplicitParameter(JPQLQuery.java:162)
                at org.datanucleus.api.jpa.JPAQuery.setParameter(JPAQuery.java:509)
                at org.datanucleus.api.jpa.JPAQuery.setParameter(JPAQuery.java:58)
                at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:133)
                at org.springframework.data.jpa.repository.query.StringQueryParameterBinder.bind(StringQueryParameterBinder.java:61)
                at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:110)
                at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:153)
                at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:144)
                at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.doCreateQuery(AbstractStringBasedJpaQuery.java:68)
                at org.springframework.data.jpa.repository.query.AbstractJpaQuery.createQuery(AbstractJpaQuery.java:145)
                at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:142)
                at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:61)
                at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:96)
        I can't reach the parameters assignment phase. And where is the Query's package? I'm using the 4.0.0-m3 version and didn't find org.datanucleus.store.query.Query class.
        Regards,

        Gilberto

        Comment


      • #5
        Here it is: https://www.dropbox.com/s/fe71tfwuj3...g-4-0-0-m3.png
        I've setup Hibernate in this project too and, as the eclipselink, all tests pass.

        This time I've enabled the org.springframework.data(spring-data-jpa) log and I can see the spring-data query in the log as well:https://dl.dropboxusercontent.com/u/...g-4-0-0-m3.txt

        Comment


        • gilbertoca
          gilbertoca commented
          Editing a comment
          Now I'm curious! Can you show me where in my own code there are such a mix?

      • #6
        Hi,

        After DataNucleus release(4.0.0-release)! Now we don't have any database related problem.
        Regards,
        Gilberto
        DataNucleus, Java, Persistence, JDO, JPA, ORM, RDBMS, XML, LDAP, Cassandra, BigTable, HBase, MongoDB, Neo4j

        Comment

        Working...
        X