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

Repository update does not work as upsert when using @Where on entity or repository #1243

Open
nfode opened this issue Dec 13, 2021 · 1 comment
Assignees
Labels
status: next major version The issue will be considered for the next major version type: improvement A minor improvement to an existing feature
Milestone

Comments

@nfode
Copy link

nfode commented Dec 13, 2021

Expected Behavior

When using @Where on an entity or a repository, the update method should also create an entity if it does not exist.
This behavior exists when using an entity + repository without any @Where Annotations, and also worked with @Where annotations in the micronaut-data version 3.0.1 (micronaut 3.0.2).

Actual Behaviour

When using @Where either on the entity or the repository, update does not persist an entity if it has not existed before.

Here are some tests: https://github.com/flip-corp/micronaut-bugreports-demo/blob/update_does_not_save_anymore/src/test/kotlin/com/example/db/UserRepositoryTest.kt

All of them should pass, but all except the one using a repository and entity without @Where fail.

Steps To Reproduce

  1. Checkout https://github.com/flip-corp/micronaut-bugreports-demo/tree/update_does_not_save_anymore
  2. Run the tests here: https://github.com/flip-corp/micronaut-bugreports-demo/blob/update_does_not_save_anymore/src/test/kotlin/com/example/db/UserRepositoryTest.kt

Environment Information

  • JDK Version: 17

Example Application

https://github.com/flip-corp/micronaut-bugreports-demo/tree/update_does_not_save_anymore

Version

micronaut 3.2.0 and micronaut-data 3.2.1

@dstepanov
Copy link
Contributor

Not sure if this is a bug, the problem here is that we are using EntityManager#merge for the update operation.
When you define @Where we are creating a custom update query and trying to execute it, otherwise merge is invoked.

I think choosing merge operation by default for the update wasn't the best decision, we should probably revisit it in the next major version and use Session#update.

@dstepanov dstepanov added the status: next major version The issue will be considered for the next major version label Dec 20, 2021
@dstepanov dstepanov added this to the 4.0.0 milestone Dec 20, 2021
@dstepanov dstepanov added the type: improvement A minor improvement to an existing feature label Dec 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: next major version The issue will be considered for the next major version type: improvement A minor improvement to an existing feature
Projects
Status: Todo
Development

No branches or pull requests

2 participants