そごうソフトウェア研究所

SOA、開発プロセス、ITアーキテクチャなどについて書いています。Twitterやってます@rsogo

3.4.2 Version Attributes

The Version field or property is used by the persistence provider to perform optimistic locking. It is accessed and/or set by the persistence provider in the course of performing lifecycle operations on the entity instance. An entity is automatically enabled for optimistic locking if it has a property or field mapped with a Version mapping.

Versionフィールドやプロパティはパーシステントプロバイダによって、楽観的ロックを行うために使われる。エンティティのインスタンスに対するライフサイクル操作(具体的にどんな操作だろう。Versionなので、update/merge等で良いのかな?)を行うために使用される。もし、Versionにマッピングされたプロパティや、フィールドを持っているなら、エンティティの楽観的ロックは自動的にできる。

An entity may access the state of its version field or property or export a method for use by the application to access the version, but must not modify the version value[17]. Only the persistence provider is permitted to set or update the value of the version attribute in the object.

(ユーザ)アプリケーションはVersion属性/プロパティ/メソッドにアクセスしてもいいけど、値を変更してはダメ。パーシステンス・プロバイダだけが、Version属性の値をセットしたり、更新していいよ。

The version attribute is updated by the persistence provider runtime when the object is written to the database. All non-relationship fields and properties and all relationships owned by the entity are included in version checks.

(以下、書きかけ。。。)

Version属性は、そのオブジェクトがデータベースに書き込まれたときにパーシステンス・プロバイダに更新される。Versionを更新するためのチェックは、全ての関連性のないフィールド、プロパティと全ての関連性のあるものは、バージョン確認に含まれるエンティティによて保持される。

↑意味分からん。

The persistence provider's implementation of the merge operation must examine the version attribute when an entity is being merged and throw an OptimisticLockException if it is discovered that the object being merged is a stale copy of the entity

マージ処理のパーシステンス・プロバイダの実装はバージョン属性を検証しなければならない。もし、そのマージしようとしているオブジェクトが古いものだとわかったら、OptimisticLockExceptionが発生する。

―i.e. that the entity has been updated since the entity became detached. Depending on the implementation strategy used, it is possible that this exception may not be thrown until flush is called or commit time, whichever happens first.

例えば、エンティティがデタッチになってから、アップデートされた場合。
例外がflushが呼ばれるまで起こらないのか、コミット時まで起こらないのか、それとも最初に起こるのかは実装に依存する。

The persistence provider runtime is only required to use the version attribute when performing optimistic lock checking. Persistence provider implementations may provide additional mechanisms beside version attributes to enable optimistic lock checking. However, support for such mechanisms is not required of an implementation of this specification.[18]

パーシステンス・プロバイダ実行時は、楽観的ロックのチェックを処理するときにバージョン属性を使用することが要求されているのみである。パーシステンス・プロバイダの実装は楽観的ロックをチェック可能にするためのバージョン属性の他に追加の機構を提供してもかまわない。

しかし、そのような機構のサポートはこの仕様の実装には要求されない。

If only some entities contain version attributes, the persistence provider runtime is required to check those entities for which version attributes have been specified. The consistency of the object graph is not guaranteed, but the absence of version attributes on some of the entities will not stop operations from completing.

もし、いくつかのエンティティがバージョン属性を保有しているのみならば、パーシステンス・プロバイダはバージョン属性が指定されているこれらのエンティティについて、チェックを行うことが要求されている。

オブジェクトグラフの一貫性は、保証されませんが、エンティティのいくつかについてのバージョン属性の欠如は完了してから、処理を停止するかもしれない。