Skip to content

Add support for Optimistic Locking using @Version #93

@roboticscm

Description

@roboticscm

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions