java oracle 事务 锁_java – 在Oracle上使用Hibernate进行死锁事务

我有以下(简化)Hibernate实体:

@Entity(name = "Foo")

public class Foo {

@Id

@GeneratedValue

public int id;

@OneToOne

public Bar bar;

}

和,

@Entity(name = "Bar")

public class Bar {

@Id

@GeneratedValue

public int id;

@Column

public String field;

@Version

public int version;

}

我在一个看起来大致如下的事务中更新这些实体:

Bar bar = findBar(em);

Foo foo = findFoo(em);

bar.field = "updated value";

if () {

em.remove(foo);

}

em.detach(bar);

em.merge(bar);

请注意,em.remove(foo)有时仅被调用,而bar始终更新.

我偶然注意到ORA-00060:运行应用程序时死锁检测到错误.转储似乎暗示两个死锁的会话被锁定在em.merge(bar)和em.remove(foo)上,但我不明白为什么会出现这种情况.

这段代码怎么会死锁?有没有办法重组它避免死锁?

以下是跟踪中的一些额外信息:

Deadlock graph:

---------Blocker(s)-------- ---------Waiter(s)---------

Resource Name process session holds waits process session holds waits

TX-00040005-000010dd 73 6557 X 81 6498 X

TX-00010018-000010bd 81 6498 X 73 6557 X

session 6557: DID 0001-0049-000002F5 session 6498: DID 0001-0051-0000030E

session 6498: DID 0001-0051-0000030E session 6557: DID 0001-0049-000002F5

Rows waited on:

Session 6557: obj - rowid = 00004797 - AAAEeXAB4AAADH0BBP

(dictionary objn - 18331, file - 120, block - 12788, slot - 15)

Session 6498: obj - rowid = 00007191 - AAAHGRAB4AAAACBBBo

(dictionary objn - 29041, file - 120, block - 129, slot - 40)

----- Information for the OTHER waiting sessions -----

Session 6498:

program: JDBC Thin Client

application name: JDBC Thin Client, hash value=2546894660

current SQL:

delete from Foo where id=:1

----- Current SQL Statement for this session (sql_id=sfasdgasdgaf) -----

update Bar set field=:1, version=:2 where id=:3 and version=:4

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值