javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: Error calling CallableStatement.getMoreResults

Hibernate JIRA | Vlad Mihalcea | 7 months ago
  1. 0

    Now that stored procedure tests have been added, I noticed that on 5.2.0 neither one of the REFCURSOR tests works anymore. To replicate it, first set up tests to run on PostgreSQL: {noformat} > gradle clean testClasses -Pdb=pgsql {noformat} Then run the {{org.hibernate.test.procedure.PostgreSQLStoredProcedureTest#testStoredProcedureOutParameter}} test. You'll get the following error: {noformat} javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: Error calling CallableStatement.getMoreResults at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155) at org.hibernate.procedure.internal.ProcedureCallImpl.execute(ProcedureCallImpl.java:643) at org.hibernate.test.procedure.PostgreSQLStoredProcedureTest.testStoredProcedureOutParameter(PostgreSQLStoredProcedureTest.java:184) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) {noformat} Because the input parameters are doubled: {code:java} 13:28:46,836 DEBUG SQL:92 - {call sp_count_phones(?,?,?,?)} 13:28:46,838 TRACE BasicBinder:65 - binding parameter [1] as [BIGINT] - [1] 13:28:46,838 TRACE BasicBinder:65 - binding parameter [2] as [BIGINT] - [1] 13:28:46,844 WARN SqlExceptionHelper:129 - SQL Error: 0, SQLState: 42883 {code} Even if there were only two registrations: {code:java} StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_count_phones" ); query.registerStoredProcedureParameter( "personId", Long.class, ParameterMode.IN ); query.registerStoredProcedureParameter( "phoneCount", Long.class, ParameterMode.OUT ); query.setParameter( "personId", 1L ); query.execute(); Long phoneCount = (Long) query.getOutputParameterValue( "phoneCount" ); {code} Most likely, the issue comes from {{ProcedureCallImpl}} where in the {{registerStoredProcedureParameter}} method, the {{registerParameter}} method is called twice: {code:java} registerParameter( (ParameterRegistrationImplementor) registerParameter( parameterName, type, mode ) ); {code}

    Hibernate JIRA | 7 months ago | Vlad Mihalcea
    javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: Error calling CallableStatement.getMoreResults
  2. 0

    Now that stored procedure tests have been added, I noticed that on 5.2.0 neither one of the REFCURSOR tests works anymore. To replicate it, first set up tests to run on PostgreSQL: {noformat} > gradle clean testClasses -Pdb=pgsql {noformat} Then run the {{org.hibernate.test.procedure.PostgreSQLStoredProcedureTest#testStoredProcedureOutParameter}} test. You'll get the following error: {noformat} javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: Error calling CallableStatement.getMoreResults at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155) at org.hibernate.procedure.internal.ProcedureCallImpl.execute(ProcedureCallImpl.java:643) at org.hibernate.test.procedure.PostgreSQLStoredProcedureTest.testStoredProcedureOutParameter(PostgreSQLStoredProcedureTest.java:184) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) {noformat} Because the input parameters are doubled: {code:java} 13:28:46,836 DEBUG SQL:92 - {call sp_count_phones(?,?,?,?)} 13:28:46,838 TRACE BasicBinder:65 - binding parameter [1] as [BIGINT] - [1] 13:28:46,838 TRACE BasicBinder:65 - binding parameter [2] as [BIGINT] - [1] 13:28:46,844 WARN SqlExceptionHelper:129 - SQL Error: 0, SQLState: 42883 {code} Even if there were only two registrations: {code:java} StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_count_phones" ); query.registerStoredProcedureParameter( "personId", Long.class, ParameterMode.IN ); query.registerStoredProcedureParameter( "phoneCount", Long.class, ParameterMode.OUT ); query.setParameter( "personId", 1L ); query.execute(); Long phoneCount = (Long) query.getOutputParameterValue( "phoneCount" ); {code} Most likely, the issue comes from {{ProcedureCallImpl}} where in the {{registerStoredProcedureParameter}} method, the {{registerParameter}} method is called twice: {code:java} registerParameter( (ParameterRegistrationImplementor) registerParameter( parameterName, type, mode ) ); {code}

    Hibernate JIRA | 7 months ago | Vlad Mihalcea
    javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: Error calling CallableStatement.getMoreResults
  3. 0

    Spring Data error on Query after detach

    Stack Overflow | 2 weeks ago | Gavi
    javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.myapp.core.model.Location
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    {code} ... javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Error calling CallableStatement.getMoreResults at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602) at org.hibernate.jpa.internal.StoredProcedureQueryImpl.execute(StoredProcedureQueryImpl.java:224) at support.hibernate.entity.TestHibernate.test(TestHibernate.java:76) ... Caused by: org.hibernate.exception.GenericJDBCException: Error calling CallableStatement.getMoreResults at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) at org.hibernate.result.internal.OutputsImpl.convert(OutputsImpl.java:79) at org.hibernate.result.internal.OutputsImpl.<init>(OutputsImpl.java:56) at org.hibernate.procedure.internal.ProcedureOutputsImpl.<init>(ProcedureOutputsImpl.java:32) at org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs(ProcedureCallImpl.java:411) at org.hibernate.procedure.internal.ProcedureCallImpl.getOutputs(ProcedureCallImpl.java:363) at org.hibernate.jpa.internal.StoredProcedureQueryImpl.outputs(StoredProcedureQueryImpl.java:234) at org.hibernate.jpa.internal.StoredProcedureQueryImpl.execute(StoredProcedureQueryImpl.java:217) ... 32 more Caused by: java.sql.SQLException: The number of parameter names does not match the number of registered praremeters at oracle.jdbc.driver.OracleSql.setNamedParameters(OracleSql.java:199) at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4753) at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1378) at org.hibernate.result.internal.OutputsImpl.<init>(OutputsImpl.java:52) ... {code} Have also seen a variant exception (from Oracle code): {{java.sql.SQLException: operation not allowed: Ordinal binding and Named binding cannot be combined!}} Simple stored procedure with a single input and single output parameter: {{create or replace PROCEDURE TEST_PROC(param1 CHAR, retval OUT INTEGER) AS BEGIN retval:=1; END TEST_PROC;}} {code} final StoredProcedureQuery query = entityManager.createStoredProcedureQuery("TEST_PROC"); query.registerStoredProcedureParameter("param1", String.class, ParameterMode.IN); query.registerStoredProcedureParameter("retval", Integer.class, ParameterMode.OUT); query.setParameter("param1", "test"); final Integer retval = (Integer) query.getOutputParameterValue("retval"); // this fails {code} Seems to have been introduced in 5.0.8.

    Hibernate JIRA | 7 months ago | Stephen Fikes
    javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Error calling CallableStatement.getMoreResults
  6. 0

    {code} ... javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Error calling CallableStatement.getMoreResults at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602) at org.hibernate.jpa.internal.StoredProcedureQueryImpl.execute(StoredProcedureQueryImpl.java:224) at support.hibernate.entity.TestHibernate.test(TestHibernate.java:76) ... Caused by: org.hibernate.exception.GenericJDBCException: Error calling CallableStatement.getMoreResults at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) at org.hibernate.result.internal.OutputsImpl.convert(OutputsImpl.java:79) at org.hibernate.result.internal.OutputsImpl.<init>(OutputsImpl.java:56) at org.hibernate.procedure.internal.ProcedureOutputsImpl.<init>(ProcedureOutputsImpl.java:32) at org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs(ProcedureCallImpl.java:411) at org.hibernate.procedure.internal.ProcedureCallImpl.getOutputs(ProcedureCallImpl.java:363) at org.hibernate.jpa.internal.StoredProcedureQueryImpl.outputs(StoredProcedureQueryImpl.java:234) at org.hibernate.jpa.internal.StoredProcedureQueryImpl.execute(StoredProcedureQueryImpl.java:217) ... 32 more Caused by: java.sql.SQLException: The number of parameter names does not match the number of registered praremeters at oracle.jdbc.driver.OracleSql.setNamedParameters(OracleSql.java:199) at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4753) at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1378) at org.hibernate.result.internal.OutputsImpl.<init>(OutputsImpl.java:52) ... {code} Have also seen a variant exception (from Oracle code): {{java.sql.SQLException: operation not allowed: Ordinal binding and Named binding cannot be combined!}} Simple stored procedure with a single input and single output parameter: {{create or replace PROCEDURE TEST_PROC(param1 CHAR, retval OUT INTEGER) AS BEGIN retval:=1; END TEST_PROC;}} {code} final StoredProcedureQuery query = entityManager.createStoredProcedureQuery("TEST_PROC"); query.registerStoredProcedureParameter("param1", String.class, ParameterMode.IN); query.registerStoredProcedureParameter("retval", Integer.class, ParameterMode.OUT); query.setParameter("param1", "test"); final Integer retval = (Integer) query.getOutputParameterValue("retval"); // this fails {code} Seems to have been introduced in 5.0.8.

    Hibernate JIRA | 7 months ago | Stephen Fikes
    javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Error calling CallableStatement.getMoreResults

    1 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. javax.persistence.PersistenceException

      org.hibernate.exception.SQLGrammarException: Error calling CallableStatement.getMoreResults

      at org.hibernate.internal.ExceptionConverterImpl.convert()
    2. Hibernate
      ExceptionConverterImpl.convert
      1. org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147)
      2. org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
      2 frames
    3. org.hibernate.procedure
      ProcedureCallImpl.execute
      1. org.hibernate.procedure.internal.ProcedureCallImpl.execute(ProcedureCallImpl.java:643)
      1 frame
    4. org.hibernate.test
      PostgreSQLStoredProcedureTest.testStoredProcedureOutParameter
      1. org.hibernate.test.procedure.PostgreSQLStoredProcedureTest.testStoredProcedureOutParameter(PostgreSQLStoredProcedureTest.java:184)
      1 frame
    5. Java RT
      NativeMethodAccessorImpl.invoke0
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      1 frame