简体   繁体   English

JPA和MySQL的并发事务

[英]JPA and concurrent transactions with MySQL

I am not a DB expert, so maybe somebody can help me out with the following. 我不是数据库专家,所以也许有人可以帮助我解决以下问题。 I use JPA icm MySQL on the Play! 我在Play上使用JPA icm MySQL! Framework. 框架。

As I in the past ran into problems with DB locks on a data collection routine, I made this routine read-only. 过去我在数据收集例程中遇到DB锁问题时,我将此例程设为只读。 Now when I need to make changes from this routine I do it concurrently. 现在,当我需要从此例程进行更改时,我会同时进行。 Worked fine so far, but now I run into a problem. 到目前为止工作还不错,但是现在我遇到了问题。 When a new user connects a record is created and the ID passed back. 当新用户连接时,将创建一条记录,并将ID传回。 But I need to get the Model, not just the id. 但是我需要获取模型,而不仅仅是ID。

When I search for the 'id' on my test environment this is fine, I just search for it (mem db) but with MYSQL the EM returns with nothing. 当我在测试环境中搜索“ id”时,这很好,我只是搜索了它(mem db),但是使用MYSQL时,EM却一无所获。 It seems to me that with JPA-MySQL no changes made before the transaction start (even if bread-only) are included in future searches. 在我看来,对于JPA-MySQL,在事务开始之前没有进行任何更改(即使只有面包)也不会包含在将来的搜索中。

Is this correct, and is there a way around this? 这是正确的,并且有办法解决吗? I can rewrite the procedure to make it readable again, and see if I can optimise it more so it would not result in other threads (or server) to run into a problem in obtaining a db lock. 我可以重写该过程以使其再次可读,然后查看是否可以对其进行更多优化,以免导致其他线程(或服务器)在获取数据库锁时遇到问题。 Possibly the best in the long term, but I am looking for a quicker solution for the moment. 从长远来看,可能是最好的选择,但是我目前正在寻找一种更快的解决方案。

The Transaction Isolation Level was set too high. 事务隔离级别设置得太高。 Changing it solved the problem. 更改它可以解决问题。 In the Play! 在剧中! Framework (1.2.5) it can be done like this: 框架(1.2.5)可以这样完成:

%prod-test.db.isolation=READ_COMMITTED

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

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