确保在Hibernate / HSQLDB中使用并发锁定进行更新?

时间:2022-04-22 00:29:51

I have multiple machines running a service that is updating and reading values from a database using Hibernate.

我有多台机器运行服务,使用Hibernate更新和读取数据库中的值。

Whenever I need to update a DB value in my service, I use an upgrade nowait lock, and if I can't get the lock, I just retry later.

每当我需要在服务中更新数据库值时,我都会使用升级nowait锁,如果我无法获得锁,我只是稍后重试。

void lock(Job job) {
    sessionFactory.session.lock(job, LockMode.UPGRADE_NOWAIT);
}

There is one place in my service where I must update the DB value there, and I cannot retry. I figured I'd just use a normal upgrade lock in those spots, and it can just wait however long it needs to update the value.

我的服务中有一个地方我必须在那里更新数据库值,我无法重试。我想我只是在这些位置使用普通的升级锁,它可以等待它需要更新值。

void waitForLock(Job job) {
    sessionFactory.session.lock(job, LockMode.UPGRADE);
}

But now I see this error pop up sometimes...

但现在我看到这个错误有时弹出......

org.hibernate.dialect.HSQLDialect - HSQLDB supports only READ_UNCOMMITTED isolation

Is there a way to guarantee that this value will be updated first time using Hibernate?

有没有办法保证第一次使用Hibernate更新此值?

1 个解决方案

#1


1  

You are using an old version of HSQLDB which does not support transaction isolation. Use the latest version (2.2.8 or later) which does.

您正在使用不支持事务隔离的旧版HSQLDB。使用最新版本(2.2.8或更高版本)。

#1


1  

You are using an old version of HSQLDB which does not support transaction isolation. Use the latest version (2.2.8 or later) which does.

您正在使用不支持事务隔离的旧版HSQLDB。使用最新版本(2.2.8或更高版本)。