optimistic-locking

Optimistic locking batch update

孤者浪人 提交于 2021-02-19 06:22:27
问题 How to use optimistic locking with batch updates? I am using SimpleJdbcTemplate and for a single row I can build update sql that increments version column value and includes version in WHERE clause. Unfortunately the result int[] updated = simpleJdbcTemplate.batchUpdate does not contain rowcounts when using oracle driver. All elements are -2 indicating unknown rowcount. Is there some other, more performant way of doing this than executing all updates individually? These batches contain an

Will hibernate increment version if I add/remove/update element of dependable collection?

蹲街弑〆低调 提交于 2021-01-29 22:19:20
问题 I am learning hibernate optimistic lock mechanism and I haven't found answer on my question in user guide Let's say we have entity like this: @Entity class Employee{ @Version Long versionField; List<Employee> subordinates; ... } And somewhere we have following code: Employee sub = .... Emplyee emp = readEmploye(); emp.getSubordinates().add(sub); Can I control of version incrementation at this case ? 回答1: By default no. Since you're not changing the entity, but rather other entities that are

Will hibernate increment version if I add/remove/update element of dependable collection?

人走茶凉 提交于 2021-01-29 21:28:14
问题 I am learning hibernate optimistic lock mechanism and I haven't found answer on my question in user guide Let's say we have entity like this: @Entity class Employee{ @Version Long versionField; List<Employee> subordinates; ... } And somewhere we have following code: Employee sub = .... Emplyee emp = readEmploye(); emp.getSubordinates().add(sub); Can I control of version incrementation at this case ? 回答1: By default no. Since you're not changing the entity, but rather other entities that are

How to lock on select and release lock after update is committed using spring?

左心房为你撑大大i 提交于 2021-01-29 06:07:57
问题 I have started using spring from last few months and I have a question on transactions. I have a java method inside my spring batch job which first does a select operation to get first 100 rows with status as 'NOT COMPLETED' and does a update on the selected rows to change the status to 'IN PROGRESS'. Since I'm processing around 10 million records, I want to run multiple instances of my batch job and each instance has multiple threads. For a single instance, to make sure two threads are not

Hibernate optimistic locking different behavior between Postgres and MariaDb

两盒软妹~` 提交于 2021-01-28 11:21:29
问题 I just discovered that my application behaves differently when I use optimistic locking with a Postgresql or a MariaDB database and I am wondering if somebody can explain what happens and how could I make the application work in the same way with MariaDB? I use Postgresl 10.5 and MariaDB 10.3.10 with InnoDB engine and default settings. I use Spring framework version 5.1.0 and Hibernate 5.3.6. So my code looks like this: @Entity @Getter @Setter @NoArgsConstructor public class Bla { @Id

Hibernate @Version causing database foreign key constraint failure

拜拜、爱过 提交于 2020-01-16 19:12:08
问题 I have two hibernate/JPA entities @Entity @Table(name = "conference_room", uniqueConstraints = @UniqueConstraint(columnNames = "code")) class ConferenceRoom { @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "id", unique = true, nullable = false) private Integer id; @Column(name = "code", unique = true, length = 20) private String code; @OneToMany(fetch = FetchType.LAZY, mappedBy = "conferenceRoom") @Cascade({CascadeType.ALL}) private Set<Person> people = new HashSet<Person>(); //

Intercepting @Transactional After Optimistic Lock for Asynchronous Calls in Restful App

一世执手 提交于 2020-01-14 06:22:08
问题 The question I have today is how to retry a method after the @Transactional annotation causes an Optimistic Lock Exception (OLE) and rolls back the transaction. I have asynchronous calls to a Restful application that are attempting to update a database object based on some business logic. If I get an OLE, I'd like to retry the transaction after a delay of 0.2-0.5 seconds. @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED, readOnly = false) public Response

Does the JPA optimistic locking specification support validating against a version supplied by a client

夙愿已清 提交于 2020-01-06 02:41:25
问题 Suppose I have an entity defined as follows: @Entity public class MyEntity { @Id @GeneratedValue private Integer id; @Column private String name; @Version int version; // Getters + setters } Suppose also I have a service (REST API or something similar) that allows a user to retrieve information about this entity. It returns the ID, the current name, and the current version. There is also another service that allows a user to update the name of an entity. It accepts the ID, update name, and

Optimistic concurrency out of session in NHibernate

风流意气都作罢 提交于 2020-01-03 05:05:09
问题 I'm having trouble implementing optimisitc concurrency in NHibernate in a meaningful way in a web application. Here is the desired scenario: User A opens a form to edit a record User B opens the same form to edit the same record User A saves their data User B tries to save their data but get a warning that the data has been updated. A common scenario. Here is the update code and entity mapping file: <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Entities" assembly="Domain">

Is there an alternative to ISession.Merge() that doesn't throw when using optimistic locking?

余生长醉 提交于 2019-12-24 11:29:23
问题 I've been trying to use ISession.Merge() to keep coherence between two sessions, but it fails when the merged instance has a higher Version property than the one loaded in the session (with a StaleObjectStateException). Is there an alternative method that would work when the Version fields do not match ? 回答1: Try calling: Session.Lock(string entityName, object obj, LockMode lockMode); with LockMode.Force. The remarks for that method state: This may be used to perform a version check