简体   繁体   English

Spring 数据 JdbcTemplate - 多个数据源 - 超过锁定等待超时

[英]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:我在 Spring MVC 框架中有一个带有 @Transactional 注释的服务,它调用两个不同的 DAO,使用不同的 JdbcTemplate 和不同的数据源:

  • JDBCTemplate1 (linked to Datasource1) JDBCTemplate1(链接到 Datasource1)
  • JDBCTemplate2 (linked to Datasource2) JDBCTemplate2(链接到 Datasource2)

For using the same transaction across the service, we have configured ChainedTransactionManager for both datasources.为了在服务中使用相同的事务,我们为两个数据源配置了 ChainedTransactionManager。

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.服务调用两个 Daos,一个使用 JDBCTemplate1 在一个表中创建一行,另一个 Dao 使用 JDBCTemplate2 在另一个表中创建一行,使用 JDBCTemplate1 添加的行的 PK 作为 FK。

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.似乎 MySQL 正在锁定第一个数据源的表中的行,直到提交,当我尝试在第二个数据源中将其分配为 FK 时,我无法访问它,从而产生锁定等待 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.如果我在第一个数据源的表中创建行,并在第二个数据源的表中创建行(但没有分配 PK),如果提交,两者都在整个事务中提交,如果整个事务回滚,则两者都回滚.

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.似乎由于某种原因,Transaction 无法解锁在第一个数据源中创建的行以供第二个数据源使用。

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.我认为该问题与 MySQL 与@Transactional 行为有关,但我不知道如何解决。

Thank you!谢谢!

can you remove the FK refferrence and check?你可以删除FK参考并检查吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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