質問

Suppose i have a database that is shared by multiple application.One Application uses ORM based approach(say hibernate) for persistence and another application uses sql for persistence.Both do write operations on the database.

How can we ensure concurrency control if we go for an optimistic locking option ? If the data is inserted using SQL, Will Hibernate automatically synchronize the persistent objects

役に立ちましたか?

解決

  • the apps which use SQL can go for optimistic locking manually. I will explain it below.

  • The app which use Hibernate won't know the newly inserted objects by other apps, but it can throw exceptin when it load-update the stale data and conflict with other apps. HIbernate use this way (optimistic locking) to protect updating stale data which is loaded and updated earlier by other user.

  • We can use optimistic locking manaually using verion property:

    update table1 set name='new name', version=version+1 where version=versionLoadedBeforeUpating and id=1234;

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top