optimistic-locking

How to use the Hibernate optimistic locking version property on the front end?

自古美人都是妖i 提交于 2019-12-04 17:23:24
问题 Optimistic locking using the version attribute for an entity works fine and is easy to implement: <version property="VERSION" type="int" column="EX_VERSION" /> The entity has a property of the following type: private int VERSION; public int getVERSION() { return VERSION; } public void setVERSION(int VERSION) { this.VERSION = VERSION; } So far, so good. Now service methods return a data transfer object (DTO) for the entity above, which the views display in HTML. For update pages, the VERSION

How to code optimistic and pessimistic locking from java code

孤人 提交于 2019-12-04 01:13:39
问题 I know what optimistic and pessimistic locking is, but when you write a java code how do you do it? Suppose I am using Oracle with Java, do I have any methods in JDBC that will help me do that? How will I configure this thing? Any pointers will be appreciated. 回答1: You can implement optimistic locks in your DB table in this way (this is how optimistic locking is done in Hibernate): Add integer "version" column to your table. Increase the value of this column with each update of corresponding

How to do concurrent modification testing for grails application

℡╲_俬逩灬. 提交于 2019-12-03 12:19:33
I'd like to run tests that simulate users modifying certain data at the same time for a grails application. Are there any plug-ins / tools / mechanisms I can use to do this efficiently? They don't have to be grails specific. It should be possible to fire multiple actions in parallel. I'd prefer to run the tests on functional level (so far I'm using Selenium for other tests) to see the results from the user perspective. Of course this can be done in addition to integration testing if you'd recommend to run concurrent modification tests on integration level as well. I have used Geb (http:/

JPA: OptimisticLockException and Cascading

别说谁变了你拦得住时间么 提交于 2019-12-03 08:38:44
In my current project I use Spring Data JPA with Hibernate but consider this as a more general question that should also cover "plain" JPA. I'm uncertain how I should deal with OptimisticLockException when using @Version . Due to how my application works some relationships have CascadeType.PERSIST and CascadeType.REFRESH , others also have CascadeType.MERGE . Where to handle OptimisticLockException As far as I can tell handling this on the service layer won't work especially with CascadeType.MERGE because then the offending entity could be one that needs to be handled by another service ( I

Which HTTP status code to use to reject a PUT due to optimistic locking failure

好久不见. 提交于 2019-12-03 06:59:37
问题 Assume I'd like to implement some kind of optimistic locking and use ETags to indicate the most up to date resource state. This means, clients will use an If-Match header when PUT ting for an update. According to the HTTP spec, the server has to return 412 Precondition failed if the ETag provided for the If-Match header doesn't match the current state of the resource. However, 409 Conflict seems to be closer to what I want to express semantically, especially as it gives guidelines what to

How are locking mechanisms (Pessimistic/Optimistic) related to database transaction isolation levels?

浪子不回头ぞ 提交于 2019-12-03 04:22:45
问题 I am writing a web application where two different users can update a list of things, to do list, for example. I have come to realize that, optimistic locking mechanism works best since I don't expect high contention. I was looking at transaction isolation levels and now I am a little confused. Looks like different transaction isolation levels also solve similar problems. How are these two different concepts related to each other? If possible, with a simple example. 回答1: Both of these things

Which HTTP status code to use to reject a PUT due to optimistic locking failure

若如初见. 提交于 2019-12-02 20:37:06
Assume I'd like to implement some kind of optimistic locking and use ETags to indicate the most up to date resource state. This means, clients will use an If-Match header when PUT ting for an update. According to the HTTP spec , the server has to return 412 Precondition failed if the ETag provided for the If-Match header doesn't match the current state of the resource. However, 409 Conflict seems to be closer to what I want to express semantically, especially as it gives guidelines what to include in the response. Is it terribly wrong to rather return 409 in case of a failure to match an ETag

How are locking mechanisms (Pessimistic/Optimistic) related to database transaction isolation levels?

放肆的年华 提交于 2019-12-02 17:37:34
I am writing a web application where two different users can update a list of things, to do list, for example. I have come to realize that, optimistic locking mechanism works best since I don't expect high contention. I was looking at transaction isolation levels and now I am a little confused. Looks like different transaction isolation levels also solve similar problems. How are these two different concepts related to each other? If possible, with a simple example. Both of these things are related to data consistency and concurrent access, but they are two different mechanisms. Locking

JPA @EmbeddedId: How to update part of a composite primary key?

我是研究僧i 提交于 2019-12-02 05:32:55
问题 I have a many-to-many relationship where the link table has an additional property. Hence the link table is represented by an entity class too and called Composition . The primary key of Composition is an @Embeddable linking to the according entities, eg. 2 @ManyToOne references. It can happen that a user makes an error when selecting either of the 2 references and hence the composite primary key must be updated. However due to how JPA (hibernate) works this will of course always create a new

JPA @EmbeddedId: How to update part of a composite primary key?

醉酒当歌 提交于 2019-12-01 23:59:39
I have a many-to-many relationship where the link table has an additional property. Hence the link table is represented by an entity class too and called Composition . The primary key of Composition is an @Embeddable linking to the according entities, eg. 2 @ManyToOne references. It can happen that a user makes an error when selecting either of the 2 references and hence the composite primary key must be updated. However due to how JPA (hibernate) works this will of course always create a new row (insert) instead of an update and the old Composition will still exist. The end result being that