org.hibernate.dialect.lock.PessimisticEntityLockException: could not obtain pessimistic lock

Hibernate JIRA | harry clark | 4 years ago
  1. 0

    Here is the code that starts this. I cannot debug this with the source distributed with 4.1.6. Eclipse tells me it doesn't match the .class files. Apparently incorrect SQL is being generated. Logging produces only valid SQL after it has been generated. I am using a custom SQL dialect with one trivial modification, also below. public static void main(...) { ... LockOptions lopt = new LockOptions(); lopt.setLockMode(LockMode.PESSIMISTIC_WRITE); lopt.setTimeOut(250); lopt.setScope(false); typeDao.lock(rt, lopt); } public class Dao<T, PK> implements Serializable, GenericDao<T, PK> { ... public void lock(T o, LockOptions lopt) { beginTransaction(); session.buildLockRequest(lopt).lock(o); } private Transaction beginTransaction() { session = sessionFactory.getCurrentSession(); Transaction tx = session.getTransaction(); if (! tx.isActive()) tx.begin(); return tx; } } public class KVESQLDialect extends DB2Dialect { public KVESQLDialect() { super(); registerHibernateType(Types.CHAR, 512L, StandardBasicTypes.STRING.getName()); } } May 14, 2013 9:40:46 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions WARN: SQL Error: -104, SQLState: 42601 May 14, 2013 9:40:46 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: [SQL0104] Token UPDATE was not valid. Valid tokens: EXCLUSIVE. Exception in thread "main" org.hibernate.dialect.lock.PessimisticEntityLockException: could not obtain pessimistic lock at org.hibernate.dialect.lock.PessimisticWriteSelectLockingStrategy.lock(PessimisticWriteSelectLockingStrategy.java:114) at org.hibernate.persister.entity.AbstractEntityPersister.lock(AbstractEntityPersister.java:1896) at org.hibernate.event.internal.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:99) at org.hibernate.event.internal.DefaultLockEventListener.onLock(DefaultLockEventListener.java:85) at org.hibernate.internal.SessionImpl.fireLock(SessionImpl.java:811) at org.hibernate.internal.SessionImpl.fireLock(SessionImpl.java:804) at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:172) at org.hibernate.internal.SessionImpl$LockRequestImpl.lock(SessionImpl.java:2365) at com.kve.vanguard.model.orm.dao.Dao.lock(Dao.java:258) at com.kve.locktest.main.Main.main(Main.java:46) Caused by: org.hibernate.exception.SQLGrammarException: [SQL0104] Token UPDATE was not valid. Valid tokens: EXCLUSIVE. at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:122) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:146) at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) at sun.proxy.$Proxy21.prepareStatement(Unknown Source) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$1.doPrepare(StatementPreparerImpl.java:84) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:166) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:71) at org.hibernate.dialect.lock.PessimisticWriteSelectLockingStrategy.lock(PessimisticWriteSelectLockingStrategy.java:75) ... 9 more Caused by: java.sql.SQLException: [SQL0104] Token UPDATE was not valid. Valid tokens: EXCLUSIVE. at com.ibm.as400.access.JDError.throwSQLException(JDError.java:650) at com.ibm.as400.access.JDError.throwSQLException(JDError.java:621) at com.ibm.as400.access.AS400JDBCStatement.commonPrepare(AS400JDBCStatement.java:1557) at com.ibm.as400.access.AS400JDBCPreparedStatement.<init>(AS400JDBCPreparedStatement.java:193) at com.ibm.as400.access.AS400JDBCConnection.prepareStatement(AS400JDBCConnection.java:2025) at com.ibm.as400.access.AS400JDBCConnection.prepareStatement(AS400JDBCConnection.java:1824) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:138) ... 15 more

    Hibernate JIRA | 4 years ago | harry clark
    org.hibernate.dialect.lock.PessimisticEntityLockException: could not obtain pessimistic lock
  2. 0

    Here is the code that starts this. I cannot debug this with the source distributed with 4.1.6. Eclipse tells me it doesn't match the .class files. Apparently incorrect SQL is being generated. Logging produces only valid SQL after it has been generated. I am using a custom SQL dialect with one trivial modification, also below. public static void main(...) { ... LockOptions lopt = new LockOptions(); lopt.setLockMode(LockMode.PESSIMISTIC_WRITE); lopt.setTimeOut(250); lopt.setScope(false); typeDao.lock(rt, lopt); } public class Dao<T, PK> implements Serializable, GenericDao<T, PK> { ... public void lock(T o, LockOptions lopt) { beginTransaction(); session.buildLockRequest(lopt).lock(o); } private Transaction beginTransaction() { session = sessionFactory.getCurrentSession(); Transaction tx = session.getTransaction(); if (! tx.isActive()) tx.begin(); return tx; } } public class KVESQLDialect extends DB2Dialect { public KVESQLDialect() { super(); registerHibernateType(Types.CHAR, 512L, StandardBasicTypes.STRING.getName()); } } May 14, 2013 9:40:46 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions WARN: SQL Error: -104, SQLState: 42601 May 14, 2013 9:40:46 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: [SQL0104] Token UPDATE was not valid. Valid tokens: EXCLUSIVE. Exception in thread "main" org.hibernate.dialect.lock.PessimisticEntityLockException: could not obtain pessimistic lock at org.hibernate.dialect.lock.PessimisticWriteSelectLockingStrategy.lock(PessimisticWriteSelectLockingStrategy.java:114) at org.hibernate.persister.entity.AbstractEntityPersister.lock(AbstractEntityPersister.java:1896) at org.hibernate.event.internal.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:99) at org.hibernate.event.internal.DefaultLockEventListener.onLock(DefaultLockEventListener.java:85) at org.hibernate.internal.SessionImpl.fireLock(SessionImpl.java:811) at org.hibernate.internal.SessionImpl.fireLock(SessionImpl.java:804) at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:172) at org.hibernate.internal.SessionImpl$LockRequestImpl.lock(SessionImpl.java:2365) at com.kve.vanguard.model.orm.dao.Dao.lock(Dao.java:258) at com.kve.locktest.main.Main.main(Main.java:46) Caused by: org.hibernate.exception.SQLGrammarException: [SQL0104] Token UPDATE was not valid. Valid tokens: EXCLUSIVE. at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:122) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:146) at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) at sun.proxy.$Proxy21.prepareStatement(Unknown Source) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$1.doPrepare(StatementPreparerImpl.java:84) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:166) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:71) at org.hibernate.dialect.lock.PessimisticWriteSelectLockingStrategy.lock(PessimisticWriteSelectLockingStrategy.java:75) ... 9 more Caused by: java.sql.SQLException: [SQL0104] Token UPDATE was not valid. Valid tokens: EXCLUSIVE. at com.ibm.as400.access.JDError.throwSQLException(JDError.java:650) at com.ibm.as400.access.JDError.throwSQLException(JDError.java:621) at com.ibm.as400.access.AS400JDBCStatement.commonPrepare(AS400JDBCStatement.java:1557) at com.ibm.as400.access.AS400JDBCPreparedStatement.<init>(AS400JDBCPreparedStatement.java:193) at com.ibm.as400.access.AS400JDBCConnection.prepareStatement(AS400JDBCConnection.java:2025) at com.ibm.as400.access.AS400JDBCConnection.prepareStatement(AS400JDBCConnection.java:1824) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:138) ... 15 more

    Hibernate JIRA | 4 years ago | harry clark
    org.hibernate.dialect.lock.PessimisticEntityLockException: could not obtain pessimistic lock
  3. 0

    jdbc error connecting to db2 on as400

    Oracle Community | 9 years ago | 199947
    java.sql.SQLException: [SQL0204] FILEDWH in IGEFILP80 type *FILE not found .
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    After connection is closed, and opened again, it no longer exists

    Stack Overflow | 3 years ago | sadiqmrd
    java.sql.SQLException: The connection does not exist.
  6. 0

    JDBC & Hiberntate Error in DB2 : Connection authorization failure occurred | SQL Error: -99999, SQLState: 42505

    Stack Overflow | 2 years ago
    java.sql.SQLException: Connection authorization failure occurred.

    3 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

      [SQL0104] Token UPDATE was not valid. Valid tokens: EXCLUSIVE.

      at com.ibm.as400.access.JDError.throwSQLException()
    2. JT400
      AS400JDBCConnection.prepareStatement
      1. com.ibm.as400.access.JDError.throwSQLException(JDError.java:650)
      2. com.ibm.as400.access.JDError.throwSQLException(JDError.java:621)
      3. com.ibm.as400.access.AS400JDBCStatement.commonPrepare(AS400JDBCStatement.java:1557)
      4. com.ibm.as400.access.AS400JDBCPreparedStatement.<init>(AS400JDBCPreparedStatement.java:193)
      5. com.ibm.as400.access.AS400JDBCConnection.prepareStatement(AS400JDBCConnection.java:2025)
      6. com.ibm.as400.access.AS400JDBCConnection.prepareStatement(AS400JDBCConnection.java:1824)
      6 frames
    3. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:601)
      4 frames
    4. org.hibernate.engine
      AbstractProxyHandler.invoke
      1. org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:138)
      2. org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
      2 frames
    5. sun.proxy
      $Proxy21.prepareStatement
      1. sun.proxy.$Proxy21.prepareStatement(Unknown Source)
      1 frame
    6. Hibernate
      SessionImpl$LockRequestImpl.lock
      1. org.hibernate.engine.jdbc.internal.StatementPreparerImpl$1.doPrepare(StatementPreparerImpl.java:84)
      2. org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:166)
      3. org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:71)
      4. org.hibernate.dialect.lock.PessimisticWriteSelectLockingStrategy.lock(PessimisticWriteSelectLockingStrategy.java:75)
      5. org.hibernate.persister.entity.AbstractEntityPersister.lock(AbstractEntityPersister.java:1896)
      6. org.hibernate.event.internal.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:99)
      7. org.hibernate.event.internal.DefaultLockEventListener.onLock(DefaultLockEventListener.java:85)
      8. org.hibernate.internal.SessionImpl.fireLock(SessionImpl.java:811)
      9. org.hibernate.internal.SessionImpl.fireLock(SessionImpl.java:804)
      10. org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:172)
      11. org.hibernate.internal.SessionImpl$LockRequestImpl.lock(SessionImpl.java:2365)
      11 frames
    7. com.kve.vanguard
      Dao.lock
      1. com.kve.vanguard.model.orm.dao.Dao.lock(Dao.java:258)
      1 frame
    8. com.kve.locktest
      Main.main
      1. com.kve.locktest.main.Main.main(Main.java:46)
      1 frame