简体   繁体   中英

Spring Data JdbcTemplate - Multiple Datasources - Lock wait timeout exceeded

I have a service in Spring MVC framework with @Transactional annotation, which calls two different DAO, using differents JdbcTemplate with different datasources:

  • JDBCTemplate1 (linked to Datasource1)
  • JDBCTemplate2 (linked to Datasource2)

For using the same transaction across the service, we have configured ChainedTransactionManager for both datasources.

Service calls two Daos, one creates one row in one table using JDBCTemplate1 and another Dao creates one row in another table using JDBCTemplate2, using as a FK the PK of the row added by JDBCTemplate1.

Seems MySQL is locking the row in table of the first datasource until is commited and I can't access it when trying to assign it as FK in the second datasouce producing a lock wait tiemout. Which it has no sense, since both are in the same transaction.

Transaction it self it's working fine. If I create the row in the table in the first datasource, and create the row in the table of second datasource (but without assigning the PK), both are commited in the entire transaction if commited and both are rollback if the entire transaction is rollback.

It's just seems that for some reason Transaction is not able to unlock the row created in the first datasource for being used by the second.

Any clue of what is happening? I think that problem is related to MySQL that to @Transactional behaviour, but I don't know how to fix it.

Thank you!

can you remove the FK refferrence and check?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM