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.

  • The problem appears to be that the hbm.xml file generated for two classes that have a Many-To-Many relationship does not include the attribute for the link (aka association) table name. see http://forum.hibernate.org/viewtopic.php?t=964363 When I tried to navigate across the association using the generated hbm.xml file I got this stack trace (snipped): WARNING: SQL Error: 1146, SQLState: 42S02 5/09/2006 14:00:24 org.hibernate.util.JDBCExceptionReporter logExceptions SEVERE: Table 'blah.enginemodels' doesn't exist Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.acme.model.ChassisModel.engineModels#1] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) When I added the table="<linktablename>" attribute to the "set" element the navigation succeeded. <set name="roles" inverse="true" table="lt_role_person"> <key> <column name="person_pkid" not-null="true"> <comment></comment> </column> </key> <many-to-many entity-name="nz.co.linktest.model.Role"> <column name="role_pkid" not-null="true"> <comment></comment> </column> </many-to-many> </set> I don't think the stuff in the log is related but I could be wrong so... The file workspace\org.hibernate.eclipse.console\hibernate-tools.log had something like 2006-09-02 17:59:32,812 0 [ Worker-5] WARN ibernate.cfg.reveng.JDBCReader - The JDBC driver didn't report any primary key columns in lt_e_model_c_model. Asking rev.eng. strategy 2006-09-02 17:59:32,812 0 [ Worker-5] WARN ibernate.cfg.reveng.JDBCReader - Rev.eng. strategy did not report any primary key columns for lt_e_model_c_model 2006-09-02 18:09:08,093 575281 [ Worker-1] WARN ibernate.cfg.reveng.JDBCReader - The JDBC driver didn't report any primary key columns in lt_e_model_c_model. Asking rev.eng. strategy 2006-09-02 18:09:08,109 575297 [ Worker-1] WARN ibernate.cfg.reveng.JDBCReader - Rev.eng. strategy did not report any primary key columns for lt_e_model_c_model 2006-09-03 08:03:53,718 0 [ Worker-9] WARN ibernate.cfg.reveng.JDBCReader - The JDBC driver didn't report any primary key columns in lt_e_model_c_model. Asking rev.eng. strategy 2006-09-03 08:03:53,750 32 [ Worker-9] WARN ibernate.cfg.reveng.JDBCReader - Rev.eng. strategy did not report any primary key columns for lt_e_model_c_model 2006-09-03 16:01:57,687 0 [ Worker-3] WARN ibernate.cfg.reveng.JDBCReader - The JDBC driver didn't report any primary key columns in lt_e_model_c_model. Asking rev.eng. strategy 2006-09-03 16:01:58,125 438 [ Worker-3] WARN ibernate.cfg.reveng.JDBCReader - Rev.eng. strategy did not report any primary key columns for lt_e_model_c_model 2006-09-03 16:05:27,312 209625 [ Worker-3] WARN ibernate.cfg.reveng.JDBCReader - The JDBC driver didn't report any primary key columns in lt_e_model_c_model. Asking rev.eng. strategy 2006-09-03 16:05:27,406 209719 [ Worker-3] WARN ibernate.cfg.reveng.JDBCReader - Rev.eng. strategy did not report any primary key columns for lt_e_model_c_model where lt_e_model_c_model is like the name of the link table that the reveng originally "failed" on. Interestingly there does not seem to be any similar log entries for the attached example. The file workspace\org.hibernate.eclipse.console\hibernate-console.xml-8 had something (some other stuff removed) like <?xml version="1.0" encoding="UTF-8"?><hibernate-console><configuration name="Linktest"><hibernate-config-xml location="/Linktest/src/hibernate.cfg.xml"/><classpath><path location="/Linktest/bin"/><path location="/Linktest/lib/mysql-connector-java-3.1.13-bin.jar"/></classpath></configuration></hibernate-console>
    via by Vaughn Butt,
  • The problem appears to be that the hbm.xml file generated for two classes that have a Many-To-Many relationship does not include the attribute for the link (aka association) table name. see http://forum.hibernate.org/viewtopic.php?t=964363 When I tried to navigate across the association using the generated hbm.xml file I got this stack trace (snipped): WARNING: SQL Error: 1146, SQLState: 42S02 5/09/2006 14:00:24 org.hibernate.util.JDBCExceptionReporter logExceptions SEVERE: Table 'blah.enginemodels' doesn't exist Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.acme.model.ChassisModel.engineModels#1] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) When I added the table="<linktablename>" attribute to the "set" element the navigation succeeded. <set name="roles" inverse="true" table="lt_role_person"> <key> <column name="person_pkid" not-null="true"> <comment></comment> </column> </key> <many-to-many entity-name="nz.co.linktest.model.Role"> <column name="role_pkid" not-null="true"> <comment></comment> </column> </many-to-many> </set> I don't think the stuff in the log is related but I could be wrong so... The file workspace\org.hibernate.eclipse.console\hibernate-tools.log had something like 2006-09-02 17:59:32,812 0 [ Worker-5] WARN ibernate.cfg.reveng.JDBCReader - The JDBC driver didn't report any primary key columns in lt_e_model_c_model. Asking rev.eng. strategy 2006-09-02 17:59:32,812 0 [ Worker-5] WARN ibernate.cfg.reveng.JDBCReader - Rev.eng. strategy did not report any primary key columns for lt_e_model_c_model 2006-09-02 18:09:08,093 575281 [ Worker-1] WARN ibernate.cfg.reveng.JDBCReader - The JDBC driver didn't report any primary key columns in lt_e_model_c_model. Asking rev.eng. strategy 2006-09-02 18:09:08,109 575297 [ Worker-1] WARN ibernate.cfg.reveng.JDBCReader - Rev.eng. strategy did not report any primary key columns for lt_e_model_c_model 2006-09-03 08:03:53,718 0 [ Worker-9] WARN ibernate.cfg.reveng.JDBCReader - The JDBC driver didn't report any primary key columns in lt_e_model_c_model. Asking rev.eng. strategy 2006-09-03 08:03:53,750 32 [ Worker-9] WARN ibernate.cfg.reveng.JDBCReader - Rev.eng. strategy did not report any primary key columns for lt_e_model_c_model 2006-09-03 16:01:57,687 0 [ Worker-3] WARN ibernate.cfg.reveng.JDBCReader - The JDBC driver didn't report any primary key columns in lt_e_model_c_model. Asking rev.eng. strategy 2006-09-03 16:01:58,125 438 [ Worker-3] WARN ibernate.cfg.reveng.JDBCReader - Rev.eng. strategy did not report any primary key columns for lt_e_model_c_model 2006-09-03 16:05:27,312 209625 [ Worker-3] WARN ibernate.cfg.reveng.JDBCReader - The JDBC driver didn't report any primary key columns in lt_e_model_c_model. Asking rev.eng. strategy 2006-09-03 16:05:27,406 209719 [ Worker-3] WARN ibernate.cfg.reveng.JDBCReader - Rev.eng. strategy did not report any primary key columns for lt_e_model_c_model where lt_e_model_c_model is like the name of the link table that the reveng originally "failed" on. Interestingly there does not seem to be any similar log entries for the attached example. The file workspace\org.hibernate.eclipse.console\hibernate-console.xml-8 had something (some other stuff removed) like <?xml version="1.0" encoding="UTF-8"?><hibernate-console><configuration name="Linktest"><hibernate-config-xml location="/Linktest/src/hibernate.cfg.xml"/><classpath><path location="/Linktest/bin"/><path location="/Linktest/lib/mysql-connector-java-3.1.13-bin.jar"/></classpath></configuration></hibernate-console>
    via by Vaughn Butt,
  • In column - 拨云剑文章搜索
    via by Unknown author,
  • In an INSERT, aliases defined in the top most FROM clause incorrectly have their references in subqueries replaced by the table name. For example, a query such as: HQL: insert into Foo (id, someInt) select bar.id as id, bar.someInt as someInt from Bar bar where exists ( select innerbar from Bar innerbar where innerbar.id=bar.id ) becomes, HSQLDB SQL: insert into Foo ( id, someInt ) select aliastable0_.id as col_0_0_, aliastable0_.someInt as col_1_0_ from Bar aliastable0_ where exists (select id from Bar aliastable1_ where aliastable1_.id=Bar.id) Note the use of 'Bar.id' instead of 'aliastable0_.id' resulting in the following exception: org.hibernate.exception.SQLGrammarException: could not execute update query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:87) at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:398) at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259) at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1142) at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94) ... Caused by: java.sql.SQLException: Column not found: BAR.ID in statement [insert into Foo ( id, someInt ) select aliastable0_.id as col_0_0_, aliastable0_.someInt as col_1_0_ from Bar aliastable0_ where exists (select id from Bar aliastable1_ where aliastable1_.id=Bar.id)] at org.hsqldb.jdbc.Util.throwError(Unknown Source) at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source) at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source) at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:528) at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:95) at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:88) at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:65) ... 27 more This substitution is not always inappropriate, for example DELETE requires the replacement: HQL: delete from Bar bar where exists ( select innerbar from Bar innerbar where bar.id=innerbar.id ) HSQLDB SQL: delete from Bar where exists ( select id from Bar insertinto1_ where Bar.id=insertinto1_.id) However, I cannot think of a case where this behavior would be necessary for an INSERT, but perhaps there is one I haven't considered. Judging from the logs, it looks as though this may have worked at one point but broke due to a fix for http://opensource.atlassian.com/projects/hibernate/browse/HHH-1419. I have attached a patch for this issue, which includes an added test for it. The fix causes aliases in an INSERT to be handled in the same manner as for a SELECT. Tested on HSQLDB and MySQL with all tests passing. The issue exists in both the http://anonsvn.jboss.org/repos/hibernate/core/branches/Branch_3_2/ and http://anonsvn.jboss.org/repos/hibernate/core/branches/Branch_3_3/ branches (both of which I've included patches for), and may exist in the http://anonsvn.jboss.org/repos/hibernate/core/trunk/ as well, but I couldn't get it to build for me. Let me know if there are any issues with the patch--especially with regard to unintended side effects--and I'll gladly look into resolving them.
    via by John Trimble,
    • org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.acme.model.ChassisModel.engineModels#1] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)

    Users with the same issue

    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    2 more bugmates