Skip to content

Add support for Optimistic Locking using @Version #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
roboticscm opened this issue Apr 11, 2019 · 8 comments
Closed

Add support for Optimistic Locking using @Version #93

roboticscm opened this issue Apr 11, 2019 · 8 comments
Labels
type: enhancement A general enhancement

Comments

@roboticscm
Copy link

roboticscm commented Apr 11, 2019

I have an entity bellow:

@Data 
@NoArgsConstructor
@Table
public class Role {
	@Id
	private Long id;
	private String name;
	@Version
	private Long version = 0L;
	public Role(String name) {
		this.name = name;
	}
}

And controller like this:

@RequestMapping("/api/role/save")
public Mono<Role> save(@RequestBody Role role){
	return roleRepo.save(role);
}

When I save a Role without @Version everything is fine
But when I add @Version, it throws exception like this:

java.lang.IllegalArgumentException: Could not obtain required identifier from entity Role(id=null, name=ADMIN, version=0)!
	at org.springframework.data.repository.core.EntityInformation.getRequiredId(EntityInformation.java:65) ~[spring-data-commons-2.2.0.M2.jar:2.2.0.M2]
	at org.springframework.data.r2dbc.repository.support.SimpleR2dbcRepository.save(SimpleR2dbcRepository.java:72) ~[spring-data-r2dbc-1.0.0.M1.jar:1.0.0.M1]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_201]

Source code demo:
https://github.com/roboticscm/r2dbc-reactive-redis.git

@mp911de
Copy link
Member

mp911de commented Apr 11, 2019

Please checkout how to format code and logs to keep the issue readable. Thank you.

@mp911de
Copy link
Member

mp911de commented Apr 11, 2019

Potentially related to #87.

@mp911de mp911de added the status: waiting-for-triage An issue we've not yet triaged label Apr 11, 2019
@roboticscm
Copy link
Author

Maybe the #87 and #93 are the same. Exceptions occured after I add @Version, the @id works fine.

@mp911de
Copy link
Member

mp911de commented Apr 11, 2019

Still, we need to sort out two things: The one is a bug that happens when you add @Version. The other issue is optimistic locking support which is not in place yet.

@mp911de mp911de changed the title Does Spring-data-r2dbc work with @Version(org.springframework.data.annotation.Version)? Add support for Optimistic Locking using @Version Apr 11, 2019
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 11, 2019
@schauder
Copy link
Contributor

This relates to https://jira.spring.io/browse/DATAJDBC-219

There is even someone working on it already spring-projects/spring-data-relational#124

@vuck3o
Copy link

vuck3o commented Jan 17, 2020

https://github.com/spring-projects/spring-data-jdbc supports optimistic locking since version 2. Is there any information when optimistic locking will also be available for spring data r2dbc?

orange-buffalo added a commit to orange-buffalo/spring-data-r2dbc that referenced this issue Feb 28, 2020
orange-buffalo added a commit to orange-buffalo/spring-data-r2dbc that referenced this issue Mar 14, 2020
orange-buffalo added a commit to orange-buffalo/spring-data-r2dbc that referenced this issue Mar 17, 2020
orange-buffalo added a commit to orange-buffalo/spring-data-r2dbc that referenced this issue Mar 19, 2020
orange-buffalo added a commit to orange-buffalo/spring-data-r2dbc that referenced this issue Mar 19, 2020
@RobMaskell
Copy link

Same problem, but looks like a different exception, looking forward to this being added

schauder pushed a commit that referenced this issue Apr 24, 2020
schauder added a commit that referenced this issue Apr 24, 2020
Formatting.
Added issue to test comments.

Removed the test for presence of the id in case of a potential optimistic locking exception.
A deleted row is also a case of a concurrent modification and therefore should trigger the OptimisticLockingException.

Original pull request: #314.
@schauder
Copy link
Contributor

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants