l********0 发帖数: 283 | 1 就是从数据库去取出某个值,这个值加1,然后保存回去
常规方法可以不行,因为多个线程操作的话,有同步问题
谢谢。 | b******y 发帖数: 1684 | 2 I am not familiar with Hibernate, but in row JDBC,
we use a 'version' field to prevent concurrent update.
I would imagine Hibernate would support you do that.
【在 l********0 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 就是从数据库去取出某个值,这个值加1,然后保存回去 : 常规方法可以不行,因为多个线程操作的话,有同步问题 : 谢谢。
| l********0 发帖数: 283 | 3 谢谢。
能否具体说说在jdbc中如何实现这个同步问题?
【在 b******y 的大作中提到】![](/moin_static193/solenoid/img/up.png) : I am not familiar with Hibernate, but in row JDBC, : we use a 'version' field to prevent concurrent update. : I would imagine Hibernate would support you do that.
| b******y 发帖数: 1684 | 4 obj = select * from OBJ_TABLE;
update OBJ_TABLE set name=obj.name, version = version +1
where id=1001 and version=obj.version
only 1 update will succeed.
【在 l********0 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 谢谢。 : 能否具体说说在jdbc中如何实现这个同步问题?
| t*******e 发帖数: 684 | 5 Same steps in Hibernate, using versioning for optimistic locking, get the
entity object by HQL or JPQL, incrementing the field of the entity by 1. The
beauty of Hibernate is here, you don't have to call save or update, as the
entity is in persistent state, Hibernate automatically does dirty check and
synchronize the new value with the row in the db table. | l********0 发帖数: 283 | 6 Thanks a lot.
the
The
the
and
【在 t*******e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Same steps in Hibernate, using versioning for optimistic locking, get the : entity object by HQL or JPQL, incrementing the field of the entity by 1. The : beauty of Hibernate is here, you don't have to call save or update, as the : entity is in persistent state, Hibernate automatically does dirty check and : synchronize the new value with the row in the db table.
|
|