optimistic-locking

Hibernate (JPA): how to handle StaleObjectStateException when several object has been modified and commited

心已入冬 提交于 2019-12-01 06:41:04
Consider the scenario: A Db transaction envolving more than one row from different tables with versioning. For example: A shopLists and products. Where a shopList may contain products (with their amount in the shoplist) and products have their current stock. When I insert ou edit a shopList, I want the stock of those products in the shopList to be updated to keep the stock consistant. To do that, I open a transaction, insert/update the shopList, update the stocks for each product (apply delta) and then commit the transaction. No big deal up to now. However, other user may have updated one or

How to code optimistic and pessimistic locking from java code

橙三吉。 提交于 2019-12-01 04:16:33
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. 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 row. To obtain lock, just read "version" value of the row. Add "version = obtained_version" condition to

Retry mechanism for optimistic locking (spring data + JPA)

核能气质少年 提交于 2019-12-01 03:49:22
We decided on using optimistic locking in our web application in order to increase concurrency and without the using of pessimistic locking. We are now on a lookout for retry solutions. We would like to have as little impact as possible to our current code base. One of the solutions we saw on the web is using a retry interceptor with annotation to mark a method as retry able. Problem is we would like to annotate methods that are having the @Transactional annotation on them but the interceptor fails to retry them for some reason. (the interceptor retries non transactional methods perfectly.) So

Retry mechanism for optimistic locking (spring data + JPA)

会有一股神秘感。 提交于 2019-12-01 00:48:09
问题 We decided on using optimistic locking in our web application in order to increase concurrency and without the using of pessimistic locking. We are now on a lookout for retry solutions. We would like to have as little impact as possible to our current code base. One of the solutions we saw on the web is using a retry interceptor with annotation to mark a method as retry able. Problem is we would like to annotate methods that are having the @Transactional annotation on them but the interceptor

Optimistic locking in a RESTful application

杀马特。学长 韩版系。学妹 提交于 2019-11-30 14:30:31
At work, we're developing a RESTful application where the data layer will be handled by Hibernate. But we're not sure how to handle updates on entities. We're planning to do the following: 1) client requests an entity by id 2) Hibernate loads the entity, the requested fields (always with the version) are copied to a DTO that is converted to JSON and sent to the client 3) Client manages some fields and sends the entity (with version number) back to the server. 4) Server receives the JSON that is converted to a DTO. 5) Corresponding entity is loaded from Hibernate and the DTO's props are copied

Java Solutions for Distributed Transactions and/or Data Shared in Cluster

这一生的挚爱 提交于 2019-11-30 10:13:54
问题 What are the best approaches to clustering/distributing a Java server application ? I'm looking for an approach that allows you to scale horizontally by adding more application servers, and more database servers. What technologies (software engineering techniques or specific technologies) would you suggest to approach this type of problem? What techniques do you use to design a persistence layer to scale to many readers/writers Scale application transactions and scale access to shared data

Spring Optimistic Locking:How to retry transactional method till commit is successful

て烟熏妆下的殇ゞ 提交于 2019-11-30 06:31:18
问题 I use Spring 2.5 and Hibernate JPA implementation with Java and "container" managed Transactions. I have a "after user commit" method that updates data in background and need to be committed regardless of ConcurrencyFailureException or StaleObjectStateException exception, because it will never be shown to client. In other words, need to make Optimistic Lock to Pessimistic. (Could happen if methods execution will take little bit longer and someone changed data in other transaction) I read a a

MongoDB Document Operations are Atomic and Isolated, but Are They Consistent?

假如想象 提交于 2019-11-30 03:22:26
I'm in the process of porting my application from an App Engine Datastore to a MongoDB backend and have a question regarding the consistency of "document updates." I understand that the updates on one document are all atomic and isolated, but is there a way to guarantee that they're "consistent" across different replica sets? In our application, many users can (and will) be trying to update one document at the same time by inserting a few embedded documents (objects) into it during one single update. We need to ensure these updates occur in a logically consistent manner across all replicas, i

Java Solutions for Distributed Transactions and/or Data Shared in Cluster

ぃ、小莉子 提交于 2019-11-29 19:27:57
What are the best approaches to clustering/distributing a Java server application ? I'm looking for an approach that allows you to scale horizontally by adding more application servers, and more database servers. What technologies (software engineering techniques or specific technologies) would you suggest to approach this type of problem? What techniques do you use to design a persistence layer to scale to many readers/writers Scale application transactions and scale access to shared data (best approach is to eliminate shared data; what techniques can you apply to eliminate shared data).

MongoDB Document Operations are Atomic and Isolated, but Are They Consistent?

十年热恋 提交于 2019-11-29 00:57:40
问题 I'm in the process of porting my application from an App Engine Datastore to a MongoDB backend and have a question regarding the consistency of "document updates." I understand that the updates on one document are all atomic and isolated, but is there a way to guarantee that they're "consistent" across different replica sets? In our application, many users can (and will) be trying to update one document at the same time by inserting a few embedded documents (objects) into it during one single