Redian新闻
>
请问hibernate这个功能如何实现?
avatar
请问hibernate这个功能如何实现?# Java - 爪哇娇娃
l*0
1
就是从数据库去取出某个值,这个值加1,然后保存回去
常规方法可以不行,因为多个线程操作的话,有同步问题
谢谢。
avatar
b*y
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 的大作中提到】
: 就是从数据库去取出某个值,这个值加1,然后保存回去
: 常规方法可以不行,因为多个线程操作的话,有同步问题
: 谢谢。

avatar
l*0
3
谢谢。
能否具体说说在jdbc中如何实现这个同步问题?

【在 b******y 的大作中提到】
: 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.

avatar
b*y
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 的大作中提到】
: 谢谢。
: 能否具体说说在jdbc中如何实现这个同步问题?

avatar
t*e
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.
avatar
l*0
6
Thanks a lot.

the
The
the
and

【在 t*******e 的大作中提到】
: 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.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。