org.hibernate.exception.SQLGrammarException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • I am trying to use "getNamedQuery". When I run the SQL, as shown by putting the property "hibernate.show_sql" in config file, The SQL Runs perfectly fine. but in Hibernate it is throwing an exception of "invalid Column", What is annoying is , It worked fine when I was not using named query. below is the copy of my hibernate.cfg.xml ============================== <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="connection.username">pdbread</property> <property name="connection.url"> jdbc:oracle:thin:@chi1dds1:1521:pdbdev </property> <property name="dialect"> org.hibernate.dialect.Oracle9Dialect </property> <property name="myeclipse.connection.profile">PDBDEV</property> <property name="connection.password">owner</property> <property name="hibernate.show_sql">true</property> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </property> <mapping resource="com/uscellular/shared/services/hibernate/Organization.hbm.xml" /> </session-factory> </hibernate-configuration> ======================== The Organization.hbm.xml file ===================== <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse - Hibernate Tools --> <hibernate-mapping> <class name="com.uscellular.shared.services.hibernate.Organization" table="ORGANIZATION" schema="PDBREAD"> <id name="organizationKey" type="java.lang.Long"> <column name="ORGANIZATION_KEY" precision="10" scale="0" /> <generator class="assigned" /> </id> <property name="region" type="java.lang.String"> <column name="REGION" length="30" /> </property> <property name="clusterDesc" type="java.lang.String"> <column name="CLUSTER_DESC" length="30" /> </property> <property name="submarketId" type="java.lang.String"> <column name="SUBMARKET_ID" length="3" /> </property> <property name="submarketDesc" type="java.lang.String"> <column name="SUBMARKET_DESC" length="30" /> </property> <property name="marketStatus" type="java.lang.String"> <column name="MARKET_STATUS" length="1" /> </property> <property name="dataCenter" type="java.lang.String"> <column name="DATA_CENTER" length="3" /> </property> <property name="roamingAdminFee" type="java.lang.Double"> <column name="ROAMING_ADMIN_FEE" precision="9" /> </property> <property name="networkSurcharge" type="java.lang.Double"> <column name="NETWORK_SURCHARGE" precision="9" /> </property> <property name="state911Fee" type="java.lang.Double"> <column name="STATE_911_FEE" precision="9" /> </property> <property name="state911FeeType" type="java.lang.String"> <column name="STATE_911_FEE_TYPE" length="3" /> </property> <property name="additionalComments" type="java.lang.String"> <column name="ADDITIONAL_COMMENTS" length="2000" /> </property> <property name="caresModificationDate" type="java.util.Date"> <column name="CARES_MODIFICATION_DATE" length="7" /> </property> <property name="modificationDate" type="java.util.Date"> <column name="MODIFICATION_DATE" length="7" /> </property> <property name="modificationUser" type="java.lang.String"> <column name="MODIFICATION_USER" length="10" /> </property> <property name="approvalDate" type="java.util.Date"> <column name="APPROVAL_DATE" length="7" /> </property> <property name="approvalUser" type="java.lang.String"> <column name="APPROVAL_USER" length="10" /> </property> <property name="lastReleaseDate" type="java.util.Date"> <column name="LAST_RELEASE_DATE" length="7" /> </property> <property name="clusterId" type="java.lang.Long"> <column name="CLUSTER_ID" precision="10" scale="0" not-null="true" /> </property> </class> <sql-query name="GetAllOrganization"> <return alias="Organization" class="com.uscellular.shared.services.hibernate.Organization"> <return-property name="ORGANIZATION_KEY" column="organizationKey"/> <return-property name="REGION" column="region"/> <return-property name="CLUSTER_DESC" column="clusterDesc"/> <return-property name="SUBMARKET_ID" column="submarketId"/> <return-property name="SUBMARKET_DESC" column="submarketDesc"/> <return-property name="MARKET_STATUS" column="marketStatus"/> <return-property name="DATA_CENTER" column="dataCenter"/> <return-property name="ROAMING_ADMIN_FEE" column="roamingAdminFee"/> <return-property name="NETWORK_SURCHARGE" column="networkSurcharge"/> <return-property name="STATE_911_FEE" column="state911Fee"/> <return-property name="STATE_911_FEE_TYPE" column="state911FeeType"/> <return-property name="ADDITIONAL_COMMENTS" column="additionalComments"/> <return-property name="CARES_MODIFICATION_DATE" column="caresModificationDate"/> <return-property name="MODIFICATION_DATE" column="modificationDate"/> <return-property name="MODIFICATION_USER" column="modificationUser"/> <return-property name="APPROVAL_DATE" column="approvalDate"/> <return-property name="APPROVAL_USER" column="approvalUser"/> <return-property name="LAST_RELEASE_DATE" column="lastReleaseDate"/> <return-property name="CLUSTER_ID" column="clusterId"/> </return> select organization_key AS organizationKey, region AS region, cluster_desc AS clusterDesc, submarket_id AS submarketId, submarket_desc AS submarketDesc, market_status AS marketStatus, data_center AS dataCenter, nvl(roaming_admin_fee,0) AS roamingAdminFee, nvl(network_surcharge,0) AS networkSurcharge, nvl(state_911_fee,0) AS state911Fee, state_911_fee_type AS state911FeeType, additional_comments AS additionalComments, cares_modification_date AS caresModificationDate, modification_date AS modificationDate, modification_user AS modificationUser, approval_date AS approvalDate, approval_user AS approvalUser, last_release_date AS lastReleaseDate, cluster_id AS clusterId from organization </sql-query> </hibernate-mapping> =========================== when I make a call like this >>>> public Organization[] getAll() { List<Organization> retList; Organization[] org= null; try { org.hibernate.Session s = getSession(); retList = s.getNamedQuery("GetAllOrganization").list(); org = new Organization[retList.size()]; retList.toArray(org); } catch (RuntimeException re) { log.error("get failed", re); throw re; } return org; } >>>>> I get an Exception as below Hibernate: select organization_key AS organizationKey, region AS region, cluster_desc AS clusterDesc, submarket_id AS submarketId, submarket_desc AS submarketDesc, market_status AS marketStatus, data_center AS dataCenter, nvl(roaming_admin_fee,0) AS roamingAdminFee, nvl(network_surcharge,0) AS networkSurcharge, nvl(state_911_fee,0) AS state911Fee, state_911_fee_type AS state911FeeType, additional_comments AS additionalComments, cares_modification_date AS caresModificationDate, modification_date AS modificationDate, modification_user AS modificationUser, approval_date AS approvalDate, approval_user AS approvalUser, last_release_date AS lastReleaseDate, cluster_id AS clusterId from organization <Jan 9, 2007 12:04:00 AM CST> <Warning> <org.hibernate.util.JDBCExceptionReporter> <000000> <SQL Error: 17006, SQLState: null> <Jan 9, 2007 12:04:00 AM CST> <Error> <org.hibernate.util.JDBCExceptionReporter> <000000> <Invalid column name> <Jan 9, 2007 12:04:00 AM CST> <Error> <com.uscellular.shared.services.hibernate.OrganizationDAO> <000000> <get failed org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:1518) at org.hibernate.loader.Loader.list(Loader.java:1498) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103) Truncated. see log file for complete stacktrace java.sql.SQLException: Invalid column name at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208) at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3291) at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1914) Truncated. see log file for complete stacktrace > org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:1518) at org.hibernate.loader.Loader.list(Loader.java:1498) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103) at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1340) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:151) at com.uscellular.shared.services.hibernate.OrganizationDAO.getAll(OrganizationDAO.java:68) Any help in this is appreciated, I am wondering, why this could be a problem, ( because of any mistake in my configuration or .hbm.xml file ) or something else. when the sql is perfectly running file I have tried to remove the 'AS' clause in SQL - did not work I tried to put like ' ORGANIZATION_KEY AS Organization.organizationKey ' = did not work I tried to put ' From Organization org ' alias in table name - did not work I have tried putting the Oracle schema.table name in the query - Did not work. please help !!!!!!!!!!!!!!!!!! have already spent a week worth of time on this issue already. Thanks
    via by Srikant Panda,
  • I am trying to use "getNamedQuery". When I run the SQL, as shown by putting the property "hibernate.show_sql" in config file, The SQL Runs perfectly fine. but in Hibernate it is throwing an exception of "invalid Column", What is annoying is , It worked fine when I was not using named query. below is the copy of my hibernate.cfg.xml ============================== <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="connection.username">pdbread</property> <property name="connection.url"> jdbc:oracle:thin:@chi1dds1:1521:pdbdev </property> <property name="dialect"> org.hibernate.dialect.Oracle9Dialect </property> <property name="myeclipse.connection.profile">PDBDEV</property> <property name="connection.password">owner</property> <property name="hibernate.show_sql">true</property> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </property> <mapping resource="com/uscellular/shared/services/hibernate/Organization.hbm.xml" /> </session-factory> </hibernate-configuration> ======================== The Organization.hbm.xml file ===================== <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse - Hibernate Tools --> <hibernate-mapping> <class name="com.uscellular.shared.services.hibernate.Organization" table="ORGANIZATION" schema="PDBREAD"> <id name="organizationKey" type="java.lang.Long"> <column name="ORGANIZATION_KEY" precision="10" scale="0" /> <generator class="assigned" /> </id> <property name="region" type="java.lang.String"> <column name="REGION" length="30" /> </property> <property name="clusterDesc" type="java.lang.String"> <column name="CLUSTER_DESC" length="30" /> </property> <property name="submarketId" type="java.lang.String"> <column name="SUBMARKET_ID" length="3" /> </property> <property name="submarketDesc" type="java.lang.String"> <column name="SUBMARKET_DESC" length="30" /> </property> <property name="marketStatus" type="java.lang.String"> <column name="MARKET_STATUS" length="1" /> </property> <property name="dataCenter" type="java.lang.String"> <column name="DATA_CENTER" length="3" /> </property> <property name="roamingAdminFee" type="java.lang.Double"> <column name="ROAMING_ADMIN_FEE" precision="9" /> </property> <property name="networkSurcharge" type="java.lang.Double"> <column name="NETWORK_SURCHARGE" precision="9" /> </property> <property name="state911Fee" type="java.lang.Double"> <column name="STATE_911_FEE" precision="9" /> </property> <property name="state911FeeType" type="java.lang.String"> <column name="STATE_911_FEE_TYPE" length="3" /> </property> <property name="additionalComments" type="java.lang.String"> <column name="ADDITIONAL_COMMENTS" length="2000" /> </property> <property name="caresModificationDate" type="java.util.Date"> <column name="CARES_MODIFICATION_DATE" length="7" /> </property> <property name="modificationDate" type="java.util.Date"> <column name="MODIFICATION_DATE" length="7" /> </property> <property name="modificationUser" type="java.lang.String"> <column name="MODIFICATION_USER" length="10" /> </property> <property name="approvalDate" type="java.util.Date"> <column name="APPROVAL_DATE" length="7" /> </property> <property name="approvalUser" type="java.lang.String"> <column name="APPROVAL_USER" length="10" /> </property> <property name="lastReleaseDate" type="java.util.Date"> <column name="LAST_RELEASE_DATE" length="7" /> </property> <property name="clusterId" type="java.lang.Long"> <column name="CLUSTER_ID" precision="10" scale="0" not-null="true" /> </property> </class> <sql-query name="GetAllOrganization"> <return alias="Organization" class="com.uscellular.shared.services.hibernate.Organization"> <return-property name="ORGANIZATION_KEY" column="organizationKey"/> <return-property name="REGION" column="region"/> <return-property name="CLUSTER_DESC" column="clusterDesc"/> <return-property name="SUBMARKET_ID" column="submarketId"/> <return-property name="SUBMARKET_DESC" column="submarketDesc"/> <return-property name="MARKET_STATUS" column="marketStatus"/> <return-property name="DATA_CENTER" column="dataCenter"/> <return-property name="ROAMING_ADMIN_FEE" column="roamingAdminFee"/> <return-property name="NETWORK_SURCHARGE" column="networkSurcharge"/> <return-property name="STATE_911_FEE" column="state911Fee"/> <return-property name="STATE_911_FEE_TYPE" column="state911FeeType"/> <return-property name="ADDITIONAL_COMMENTS" column="additionalComments"/> <return-property name="CARES_MODIFICATION_DATE" column="caresModificationDate"/> <return-property name="MODIFICATION_DATE" column="modificationDate"/> <return-property name="MODIFICATION_USER" column="modificationUser"/> <return-property name="APPROVAL_DATE" column="approvalDate"/> <return-property name="APPROVAL_USER" column="approvalUser"/> <return-property name="LAST_RELEASE_DATE" column="lastReleaseDate"/> <return-property name="CLUSTER_ID" column="clusterId"/> </return> select organization_key AS organizationKey, region AS region, cluster_desc AS clusterDesc, submarket_id AS submarketId, submarket_desc AS submarketDesc, market_status AS marketStatus, data_center AS dataCenter, nvl(roaming_admin_fee,0) AS roamingAdminFee, nvl(network_surcharge,0) AS networkSurcharge, nvl(state_911_fee,0) AS state911Fee, state_911_fee_type AS state911FeeType, additional_comments AS additionalComments, cares_modification_date AS caresModificationDate, modification_date AS modificationDate, modification_user AS modificationUser, approval_date AS approvalDate, approval_user AS approvalUser, last_release_date AS lastReleaseDate, cluster_id AS clusterId from organization </sql-query> </hibernate-mapping> =========================== when I make a call like this >>>> public Organization[] getAll() { List<Organization> retList; Organization[] org= null; try { org.hibernate.Session s = getSession(); retList = s.getNamedQuery("GetAllOrganization").list(); org = new Organization[retList.size()]; retList.toArray(org); } catch (RuntimeException re) { log.error("get failed", re); throw re; } return org; } >>>>> I get an Exception as below Hibernate: select organization_key AS organizationKey, region AS region, cluster_desc AS clusterDesc, submarket_id AS submarketId, submarket_desc AS submarketDesc, market_status AS marketStatus, data_center AS dataCenter, nvl(roaming_admin_fee,0) AS roamingAdminFee, nvl(network_surcharge,0) AS networkSurcharge, nvl(state_911_fee,0) AS state911Fee, state_911_fee_type AS state911FeeType, additional_comments AS additionalComments, cares_modification_date AS caresModificationDate, modification_date AS modificationDate, modification_user AS modificationUser, approval_date AS approvalDate, approval_user AS approvalUser, last_release_date AS lastReleaseDate, cluster_id AS clusterId from organization <Jan 9, 2007 12:04:00 AM CST> <Warning> <org.hibernate.util.JDBCExceptionReporter> <000000> <SQL Error: 17006, SQLState: null> <Jan 9, 2007 12:04:00 AM CST> <Error> <org.hibernate.util.JDBCExceptionReporter> <000000> <Invalid column name> <Jan 9, 2007 12:04:00 AM CST> <Error> <com.uscellular.shared.services.hibernate.OrganizationDAO> <000000> <get failed org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:1518) at org.hibernate.loader.Loader.list(Loader.java:1498) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103) Truncated. see log file for complete stacktrace java.sql.SQLException: Invalid column name at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208) at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3291) at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1914) Truncated. see log file for complete stacktrace > org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:1518) at org.hibernate.loader.Loader.list(Loader.java:1498) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103) at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1340) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:151) at com.uscellular.shared.services.hibernate.OrganizationDAO.getAll(OrganizationDAO.java:68) Any help in this is appreciated, I am wondering, why this could be a problem, ( because of any mistake in my configuration or .hbm.xml file ) or something else. when the sql is perfectly running file I have tried to remove the 'AS' clause in SQL - did not work I tried to put like ' ORGANIZATION_KEY AS Organization.organizationKey ' = did not work I tried to put ' From Organization org ' alias in table name - did not work I have tried putting the Oracle schema.table name in the query - Did not work. please help !!!!!!!!!!!!!!!!!! have already spent a week worth of time on this issue already. Thanks
    via by Srikant Panda,
  • Following query throws SQLGrammarException: String sql = "select count(distinct foo.ID) c " + " , least(foo.AMOUNT, :amount) a " + " , :amount " + " from FOO foo " + "group by least(foo.AMOUNT, :amount) " + " , :amount "; SQLQuery query = getSession().createSQLQuery(sql); query.setParameter("amount", 1); query.list(); org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:2216) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104) at org.hibernate.loader.Loader.list(Loader.java:2099) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289) at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695) at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152) ... Caused by: java.sql.SQLSyntaxErrorException: ORA-00979: not a GROUP BY expression at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:91) at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413) at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1030) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:194) at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:785) at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:860) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1186) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3381) at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3425) at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1490) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186) at org.hibernate.loader.Loader.getResultSet(Loader.java:1787) at org.hibernate.loader.Loader.doQuery(Loader.java:674) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236) at org.hibernate.loader.Loader.doList(Loader.java:2213) ... 43 more
    via by Santtu Virolainen,
    • org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:1518) at org.hibernate.loader.Loader.list(Loader.java:1498) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103) at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1340) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:151) at com.uscellular.shared.services.hibernate.OrganizationDAO.getAll(OrganizationDAO.java:68)
    No Bugmate found.