Home > Database > Mysql Tutorial > mysql先查询后插入或者更新的事务并发问题?

mysql先查询后插入或者更新的事务并发问题?

WBOY
Release: 2016-06-06 09:35:08
Original
2944 people have browsed it

mysql并发事务

在对数据进行插入更新的时候遇到一个问题,做了一个事务:
@Transaction
public void insertOrUpdate(entity){
Object o = search(entity);
if(o!=null)
update(entity);
else
insert(entity);
}
上面的伪代码在非并发态,是正常的。但是在并发的时候就会出现插入多条同样的数据,如果调高隔离级别进行控制,就会报:
Deadlock found when trying to get lock; try restarting transaction
求解决方案

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template