hibernate isolation 幻读

@transactional代表一个transaction

Isolation默认是

FAULT
          Use the default isolation level of the underlying datastore.

如果用oracle 则默认的是In the read committed isolation level, which is the default

因为今天在同一个@transactional里面查询2次同样的对象,出现不同的结果,才知道产生了幻读

  • Nonrepeatable (fuzzy) reads

    A transaction rereads data it has previously read and finds that another committed transaction has modified or deleted the data. For example, a user queries a row and then later queries the same row, only to discover that the data has changed.

     

    Read Committed Isolation Level

    In the read committed isolation level, which is the default, every query executed by a transaction sees only data committed before the query—not the transaction—began. This level of isolation is appropriate for database environments in which few transactions are likely to conflict.

    注意是在query之前commit数据会看到,而不是transaction开始之前的数据,所有在@transactional中,query之前其他transaction修改后commit的数据都会看到,也就是我发现的问题

    接着

    A query in a read committed transaction avoids reading data that commits while the query is in progress. For example, if a query is halfway through a scan of a million-row table, and if a different transaction commits an update to row 950,000, then the query does not see this change when it reads row 950,000. However, because the database does not prevent other transactions from modifying data read by a query, other transactions may change data between query executions. Thus, a transaction that runs the same query twice may experience fuzzy reads and phantoms.

    就是在query读数据的过程中,如果其他transaction修改并提交了数据,正在查询的数据是看不到变化的,而且也不会阻止其他transaction修改,再次在该transaction查询就会发现和之前的数据不一样了,也就是幻读fuzzy reads

     

     

     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值