org.hibernate.exception.SQLGrammarException: could not lock: [persistent.jpa.AssociationsClassPeer#1]

Hibernate JIRA | Guenther Demetz | 7 years ago
  1. 0

    The method SQLServerDialect#appendLockHint currently ignores the LockMode.UPGRADE_NOWAIT returning the same string as for LockMode.UPGRADE. public String appendLockHint(LockMode mode, String tableName) { if ( mode.greaterThan( LockMode.READ ) ) { // does this need holdlock also? : return tableName + " with (updlock, rowlock, holdlock)"; return tableName + " with (updlock, rowlock)"; } else { return tableName; } } As SQLServer supports the nowait option I propose the following improvement: public String appendLockHint(LockMode mode, String tableName) { if ( mode == LockMode.UPGRADE_NOWAIT) { return tableName + " with (updlock, rowlock, nowait)"; } else if ( mode.greaterThan( LockMode.READ ) ) { // does this need holdlock also? : return tableName + " with (updlock, rowlock, holdlock)"; return tableName + " with (updlock, rowlock)"; } else { return tableName; } } A test gave me a correct behaviour: if the concerning row is already locked, then after Lock request time out period exceeded following exception is thrown: org.hibernate.exception.SQLGrammarException: could not lock: [persistent.jpa.AssociationsClassPeer#1] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.dialect.lock.SelectLockingStrategy.lock(SelectLockingStrategy.java:115) at org.hibernate.persister.entity.AbstractEntityPersister.lock(AbstractEntityPersister.java:1361) at org.hibernate.event.def.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:108) at org.hibernate.event.def.DefaultLockEventListener.onLock(DefaultLockEventListener.java:87) at org.hibernate.impl.SessionImpl.fireLock(SessionImpl.java:611) at org.hibernate.impl.SessionImpl.lock(SessionImpl.java:603) ... Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Lock request time out period exceeded. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196) at com.microsoft.sqlserver.jdbc.SQLServerResultSet$FetchBuffer.nextRow(SQLServerResultSet.java:4700) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.fetchBufferNext(SQLServerResultSet.java:1683) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.next(SQLServerResultSet.java:956) at com.p6spy.engine.spy.P6ResultSet.next(P6ResultSet.java:156) at com.p6spy.engine.logging.P6LogResultSet.next(P6LogResultSet.java:124) at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:2859) at org.hibernate.dialect.lock.SelectLockingStrategy.lock(SelectLockingStrategy.java:97) ... 24 more

    Hibernate JIRA | 7 years ago | Guenther Demetz
    org.hibernate.exception.SQLGrammarException: could not lock: [persistent.jpa.AssociationsClassPeer#1]
  2. 0

    The method SQLServerDialect#appendLockHint currently ignores the LockMode.UPGRADE_NOWAIT returning the same string as for LockMode.UPGRADE. public String appendLockHint(LockMode mode, String tableName) { if ( mode.greaterThan( LockMode.READ ) ) { // does this need holdlock also? : return tableName + " with (updlock, rowlock, holdlock)"; return tableName + " with (updlock, rowlock)"; } else { return tableName; } } As SQLServer supports the nowait option I propose the following improvement: public String appendLockHint(LockMode mode, String tableName) { if ( mode == LockMode.UPGRADE_NOWAIT) { return tableName + " with (updlock, rowlock, nowait)"; } else if ( mode.greaterThan( LockMode.READ ) ) { // does this need holdlock also? : return tableName + " with (updlock, rowlock, holdlock)"; return tableName + " with (updlock, rowlock)"; } else { return tableName; } } A test gave me a correct behaviour: if the concerning row is already locked, then after Lock request time out period exceeded following exception is thrown: org.hibernate.exception.SQLGrammarException: could not lock: [persistent.jpa.AssociationsClassPeer#1] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.dialect.lock.SelectLockingStrategy.lock(SelectLockingStrategy.java:115) at org.hibernate.persister.entity.AbstractEntityPersister.lock(AbstractEntityPersister.java:1361) at org.hibernate.event.def.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:108) at org.hibernate.event.def.DefaultLockEventListener.onLock(DefaultLockEventListener.java:87) at org.hibernate.impl.SessionImpl.fireLock(SessionImpl.java:611) at org.hibernate.impl.SessionImpl.lock(SessionImpl.java:603) ... Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Lock request time out period exceeded. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196) at com.microsoft.sqlserver.jdbc.SQLServerResultSet$FetchBuffer.nextRow(SQLServerResultSet.java:4700) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.fetchBufferNext(SQLServerResultSet.java:1683) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.next(SQLServerResultSet.java:956) at com.p6spy.engine.spy.P6ResultSet.next(P6ResultSet.java:156) at com.p6spy.engine.logging.P6LogResultSet.next(P6LogResultSet.java:124) at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:2859) at org.hibernate.dialect.lock.SelectLockingStrategy.lock(SelectLockingStrategy.java:97) ... 24 more

    Hibernate JIRA | 7 years ago | Guenther Demetz
    org.hibernate.exception.SQLGrammarException: could not lock: [persistent.jpa.AssociationsClassPeer#1]
  3. 0

    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>

    Hibernate JIRA | 1 decade ago | Vaughn Butt
    org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.acme.model.ChassisModel.engineModels#1]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    6.2.3 -> 6.2.4 Broken Upgrade - Permissions Issue - Open Knowledge Management

    openkm.com | 11 months ago
    org.hibernate.exception.SQLGrammarException: could not load an entity: [com.openkm.dao.bean.Profile#1]
  6. 0

    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>

    Hibernate JIRA | 1 decade ago | Vaughn Butt
    org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.acme.model.ChassisModel.engineModels#1]

    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. org.hibernate.exception.SQLGrammarException

      could not lock: [persistent.jpa.AssociationsClassPeer#1]

      at org.hibernate.exception.SQLStateConverter.convert()
    2. Hibernate
      AbstractEntityPersister.lock
      1. org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
      2. org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
      3. org.hibernate.dialect.lock.SelectLockingStrategy.lock(SelectLockingStrategy.java:115)
      4. org.hibernate.persister.entity.AbstractEntityPersister.lock(AbstractEntityPersister.java:1361)
      4 frames
    3. Hibernate
      SessionImpl.lock
      1. org.hibernate.event.def.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:108)
      2. org.hibernate.event.def.DefaultLockEventListener.onLock(DefaultLockEventListener.java:87)
      3. org.hibernate.impl.SessionImpl.fireLock(SessionImpl.java:611)
      4. org.hibernate.impl.SessionImpl.lock(SessionImpl.java:603)
      4 frames