1 Reply Latest reply on May 13, 2009 10:41 AM by peterj

    two dataSources: Lock wait timeout exceeded

    javatwo

      we have 3 data sources(persistence units) in our app. The following exception raised in the senario:

      data source 1: create entity 1,
      entity2.setEntity1(entity1);
      data source 2: create entity 2, entity 1 is a property of entity2

      class Entity2 {

      Entity1 getEntity1()
      void setEntity1(Entity1 entity1)
      }

      Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
      17:45:38,362 ERROR [STDERR] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
      17:45:38,362 ERROR [STDERR] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
      17:45:38,362 ERROR [STDERR] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
      17:45:38,362 ERROR [STDERR] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
      17:45:38,362 ERROR [STDERR] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
      17:45:38,362 ERROR [STDERR] at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
      17:45:38,362 ERROR [STDERR] at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)
      17:45:38,362 ERROR [STDERR] at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)
      17:45:38,362 ERROR [STDERR] at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2046)
      17:45:38,362 ERROR [STDERR] at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1964)
      17:45:38,363 ERROR [STDERR] at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1949)
      17:45:38,363 ERROR [STDERR] at com.mysql.jdbc.jdbc2.optional.PreparedStatementWrapper.executeUpdate(PreparedStatementWrapper.java:874)
      17:45:38,363 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:365)
      17:45:38,363 ERROR [STDERR] at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)
      17:45:38,363 ERROR [STDERR] at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)

      Is this a bug? How to work around this?
      Thanks,
      Dave

      Enronment: JBoss 5.0.1.GA.

        • 1. Re: two dataSources: Lock wait timeout exceeded
          peterj

          Looks like data source 1 has the row for entity 1 locked and thus data source 2 cannot access that row. There are two ways to get around this (that I can think of).

          a) You could handle entity 1 and entity 2 in the same datasource.

          b) Or you will have to change the code such that data source 1 stores entity 1 and completes its transaction first. Then use data source 2 to look up entity 1 and add it to entity 2.