Ali*_*nik 2 postgresql spring hibernate transactions spring-data
有两个线程,每个线程绑定两个事务:
DEBUG o.s.orm.jpa.JpaTransactionManager - Creating new transaction with name [com.workflow.consumer.RecordEventConsumer$MockitoMock$1882263982.handleRecordsAddedEvent]: PROPAGATION_REQUIRED,ISOLATION_READ_UNCOMMITTED; ''
Creating new transaction with name [com.workflow.statemachine.action.CreateContentAction.execute]: PROPAGATION_REQUIRED,ISOLATION_READ_UNCOMMITTED; ''
两个隔离级别都是READ_UNCOMMITTED。但是当第一个线程在数据库中插入一些内容时
repository.saveAndFlush(contextObject)
Run Code Online (Sandbox Code Playgroud)
存储库在哪里JpaRepository<T, I> repository
并且有插入发生的实际日志DEBUG org.hibernate.SQL - insert into task_unit ...etc
来自第二个线程的事务仍然无法检索这个对象:
repository.getOne(id);
repository.findOne(id);
entityManager.find(class, id);
Run Code Online (Sandbox Code Playgroud)
不仅如此,我还尝试直接连接到数据库并启动
BEGIN TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT * from task_unit
Run Code Online (Sandbox Code Playgroud)
但仍然没有成功。
我错过了什么吗?
如果我正确地理解了你的问题,那么本手册的例外回答:
https://www.postgresql.org/docs/9.6/static/transaction-iso.html
在 PostgreSQL 中,您可以请求四种标准事务隔离级别中的任何一种,但在内部仅实现了三种不同的隔离级别,即PostgreSQL 的“未提交读”模式的行为类似于“已提交读”。这是因为它是将标准隔离级别映射到 PostgreSQL 的多版本并发控制架构的唯一明智的方法。
强调我的
| 归档时间: |
|
| 查看次数: |
1346 次 |
| 最近记录: |