javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query

Hibernate JIRA | Rachit | 8 years ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    [HHH-4169] @SqlResultSetMapping gives Invalid Column for columns not in select clause - Hibernate JIRA

    atlassian.net | 2 years ago
    javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
  2. 0

    Hi, A very simple usage of SqlResultSetMapping. I want to retrieve only country Name using native query. I have specified one column country name to be fetched and mapped in Object. @SqlResultSetMapping(name = "CountryCountry", entities = { @EntityResult(entityClass = Country.class, fields = { @FieldResult(name = "countryName", column = "COUNTRY_NAME") }) public void testComplexer0NativeQuery() { em = emf.createEntityManager(); Query query = em.createNativeQuery( "select iso.COUNTRY_NAME from Country iso", "CountryCountry"); List list = query.getResultList(); System.out.println(list.size()); System.out.println(list.get(0).getClass()); } Running this I get "INFO: could not read column value from result set: ISO1_2_0_; Invalid column name" exception. The whole stack trace : javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:76) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:618) at junit.framework.TestCase.runTest(TestCase.java:168) at junit.framework.TestCase.runBare(TestCase.java:134) at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:124) at junit.framework.TestSuite.runTest(TestSuite.java:232) at junit.framework.TestSuite.run(TestSuite.java:227) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Caused by: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.loader.Loader.doList(Loader.java:2231) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125) at org.hibernate.loader.Loader.list(Loader.java:2120) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:312) at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1722) at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67) ... 21 more Caused by: java.sql.SQLException: Invalid column name at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269) at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:6348) at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1557) at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1549) at org.hibernate.type.StringType.get(StringType.java:41) at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:184) at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:173) at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1121) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:588) at org.hibernate.loader.Loader.doQuery(Loader.java:724) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) at org.hibernate.loader.Loader.doList(Loader.java:2228) ... 28 more Hibernate is trying to fetch all the columns present in entity to create the object. I am only interested in column/s I have specified in "@FieldResult". If I retrieve all fields in entity, It works fine though. Thanks and Regards.

    Hibernate JIRA | 8 years ago | Rachit
    javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
  3. 0

    Hi, A very simple usage of SqlResultSetMapping. I want to retrieve only country Name using native query. I have specified one column country name to be fetched and mapped in Object. @SqlResultSetMapping(name = "CountryCountry", entities = { @EntityResult(entityClass = Country.class, fields = { @FieldResult(name = "countryName", column = "COUNTRY_NAME") }) public void testComplexer0NativeQuery() { em = emf.createEntityManager(); Query query = em.createNativeQuery( "select iso.COUNTRY_NAME from Country iso", "CountryCountry"); List list = query.getResultList(); System.out.println(list.size()); System.out.println(list.get(0).getClass()); } Running this I get "INFO: could not read column value from result set: ISO1_2_0_; Invalid column name" exception. The whole stack trace : javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:76) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:618) at junit.framework.TestCase.runTest(TestCase.java:168) at junit.framework.TestCase.runBare(TestCase.java:134) at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:124) at junit.framework.TestSuite.runTest(TestSuite.java:232) at junit.framework.TestSuite.run(TestSuite.java:227) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Caused by: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.loader.Loader.doList(Loader.java:2231) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125) at org.hibernate.loader.Loader.list(Loader.java:2120) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:312) at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1722) at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67) ... 21 more Caused by: java.sql.SQLException: Invalid column name at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269) at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:6348) at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1557) at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1549) at org.hibernate.type.StringType.get(StringType.java:41) at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:184) at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:173) at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1121) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:588) at org.hibernate.loader.Loader.doQuery(Loader.java:724) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) at org.hibernate.loader.Loader.doList(Loader.java:2228) ... 28 more Hibernate is trying to fetch all the columns present in entity to create the object. I am only interested in column/s I have specified in "@FieldResult". If I retrieve all fields in entity, It works fine though. Thanks and Regards.

    Hibernate JIRA | 8 years ago | Rachit
    javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    problem using hibernate and stored procedures for reading portion of data from database

    Coderanch | 7 years ago | poornima komanduri
    org.hibernate.exception.GenericJDBCException: could not execute query
  6. 0

    Invalid Column Name

    Coderanch | 6 years ago | pankaj semwal
    java.sql.SQLException: Invalid column name

  1. rp 1 times, last 5 months ago
27 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. java.sql.SQLException

    Invalid column name

    at oracle.jdbc.dbaccess.DBError.throwSqlException()
  2. oracle.jdbc.dbaccess
    DBError.throwSqlException
    1. oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    2. oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
    3. oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
    3 frames
  3. Oracle jdbc
    OracleResultSet.getString
    1. oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:6348)
    2. oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1557)
    3. oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1549)
    3 frames
  4. Hibernate
    CustomLoader.list
    1. org.hibernate.type.StringType.get(StringType.java:41)
    2. org.hibernate.type.NullableType.nullSafeGet(NullableType.java:184)
    3. org.hibernate.type.NullableType.nullSafeGet(NullableType.java:173)
    4. org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1121)
    5. org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:588)
    6. org.hibernate.loader.Loader.doQuery(Loader.java:724)
    7. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
    8. org.hibernate.loader.Loader.doList(Loader.java:2228)
    9. org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
    10. org.hibernate.loader.Loader.list(Loader.java:2120)
    11. org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:312)
    11 frames
  5. Hibernate
    SQLQueryImpl.list
    1. org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1722)
    2. org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
    3. org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175)
    3 frames
  6. Hibernate EJB
    QueryImpl.getResultList
    1. org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67)
    2. org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:76)
    2 frames
  7. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    4. java.lang.reflect.Method.invoke(Method.java:618)
    4 frames
  8. JUnit
    TestCase.runBare
    1. junit.framework.TestCase.runTest(TestCase.java:168)
    2. junit.framework.TestCase.runBare(TestCase.java:134)
    2 frames
  9. Spring TestContext
    ConditionalTestCase.runBare
    1. org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
    1 frame
  10. JUnit
    JUnit38ClassRunner.run
    1. junit.framework.TestResult$1.protect(TestResult.java:110)
    2. junit.framework.TestResult.runProtected(TestResult.java:128)
    3. junit.framework.TestResult.run(TestResult.java:113)
    4. junit.framework.TestCase.run(TestCase.java:124)
    5. junit.framework.TestSuite.runTest(TestSuite.java:232)
    6. junit.framework.TestSuite.run(TestSuite.java:227)
    7. org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
    7 frames
  11. JUnit4 Runner
    JUnit4TestReference.run
    1. org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
    1 frame
  12. JUnit3 Runner
    RemoteTestRunner.main
    1. org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    4. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    5. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    5 frames