Skip to content
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

Cannot use optimistic locking with Records #1197

Closed
KangoV opened this issue Oct 18, 2021 · 1 comment · Fixed by #1199
Closed

Cannot use optimistic locking with Records #1197

KangoV opened this issue Oct 18, 2021 · 1 comment · Fixed by #1199
Labels
type: bug Something isn't working

Comments

@KangoV
Copy link

KangoV commented Oct 18, 2021

Expected Behavior

When saving an instance of an Entitt mapped via a Java Record, that the version attribute would be incremented correctly

Actual Behaviour

Upon saving, the following error is observed:

io.micronaut.data.exceptions.DataAccessException: SQL Error executing INSERT: An error occurred invoking pre-persist event listeners: Cannot write a read-only property: version
	at io.micronaut.data.runtime.operations.internal.AbstractRepositoryOperations.persistOne(AbstractRepositoryOperations.java:292)
	at io.micronaut.data.jdbc.operations.DefaultJdbcRepositoryOperations.lambda$persist$16(DefaultJdbcRepositoryOperations.java:752)
	at io.micronaut.transaction.support.AbstractSynchronousTransactionManager.executeWrite(AbstractSynchronousTransactionManager.java:175)
	at io.micronaut.data.jdbc.operations.DefaultJdbcRepositoryOperations.persist(DefaultJdbcRepositoryOperations.java:750)
	at io.micronaut.data.runtime.intercept.DefaultSaveEntityInterceptor.intercept(DefaultSaveEntityInterceptor.java:45)
	at io.micronaut.data.intercept.DataIntroductionAdvice.intercept(DataIntroductionAdvice.java:114)
	at io.micronaut.data.intercept.DataIntroductionAdvice.intercept(DataIntroductionAdvice.java:88)
	at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:137)
	at io.micronaut.validation.ValidatingInterceptor.intercept(ValidatingInterceptor.java:138)
	at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:137)

Steps To Reproduce

Using following record impl:

@Introspected
@MappedEntity("customer")
public record ClientE(
  @Id UUID id,
  @Version Integer version,
  @DateCreated LocalDateTime created,
  @Nullable @DateUpdated LocalDateTime updated,
  String forename,
  String surname,
  ...
) implements InfrastructureEntity {}

Environment Information

Ubuntu 21.04
Java 16

Example Application

No response

Version

3.1.0

Notes

I've not got past this yet, but I'm wondering if @DateCreated and @DateUpdated` might suffer the same problem.

@dstepanov
Copy link
Contributor

We do have tests for @DateCreated and @DateUpdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants