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.

  • This is duplicate to HHH-951, but in my opinion this is a bug with Blocker status and I recreated it It seems that if you set any WHERE clause into HQL query it appends this WHERE clause column into SELECT part. This works fine if you just execute it, but if you for example set maximum result size for Query it will produce this HQL query as inner select and wraps it into SELECT * FROM (...) WHERE rownum <= ? query. For example: Mapping: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="Foo" table="foo" lazy="true" > <id name="id" column="id" type="integer" > <generator class="sequence" > <param name="sequence"> <![CDATA[S_FOO]> </param> </generator> </id> </class> </hibernate-mapping> Java code: Query hql = session.createQuery("FROM Foo WHERE id = 123"); hql.setMaxResultSize(2); List results query.list(); produced SQL: SELECT * FROM (SELECT foo0_.id as id12_, foo0_.ID as ID12_ FROM foo as foo0_ WHERE foo0_.id=123) WHERE rownum <= 2 Thrown Exception: [JDBCExceptionReporter] SQL Error: 918, SQLState: 42000 [JDBCExceptionReporter] ORA-00918: column ambiguously defined org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:2148) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029) at org.hibernate.loader.Loader.list(Loader.java:2024) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1129) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    via by Petri Rautakoski,
  • This is duplicate to HHH-951, but in my opinion this is a bug with Blocker status and I recreated it It seems that if you set any WHERE clause into HQL query it appends this WHERE clause column into SELECT part. This works fine if you just execute it, but if you for example set maximum result size for Query it will produce this HQL query as inner select and wraps it into SELECT * FROM (...) WHERE rownum <= ? query. For example: Mapping: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="Foo" table="foo" lazy="true" > <id name="id" column="id" type="integer" > <generator class="sequence" > <param name="sequence"> <![CDATA[S_FOO]> </param> </generator> </id> </class> </hibernate-mapping> Java code: Query hql = session.createQuery("FROM Foo WHERE id = 123"); hql.setMaxResultSize(2); List results query.list(); produced SQL: SELECT * FROM (SELECT foo0_.id as id12_, foo0_.ID as ID12_ FROM foo as foo0_ WHERE foo0_.id=123) WHERE rownum <= 2 Thrown Exception: [JDBCExceptionReporter] SQL Error: 918, SQLState: 42000 [JDBCExceptionReporter] ORA-00918: column ambiguously defined org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:2148) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029) at org.hibernate.loader.Loader.list(Loader.java:2024) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1129) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    via by Petri Rautakoski,
  • Using a NamedQuery with a composite class
    via Stack Overflow by Ascalonian
    ,
  • OpenUDDI / Mailing Lists
    via by Unknown author,
    • org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:2148) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029) at org.hibernate.loader.Loader.list(Loader.java:2024) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1129) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)

    Users with the same issue

    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    3 more bugmates