-
Notifications
You must be signed in to change notification settings - Fork 1.1k
SimpleReactiveMongoRepository#saveAll does not populate @Id property if it is immutable #3609
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
Comments
Thanks for reporting the issue. This is indeed a bug and a leftover from the time where |
petitcl
pushed a commit
to petitcl/spring-data-mongodb
that referenced
this issue
Mar 26, 2021
Make SimpleReactiveMongoRepository#saveAll(Publisher<S>) return the saved entity references instead of the original references. Closes spring-projects#3609
petitcl
added a commit
to petitcl/spring-data-mongodb
that referenced
this issue
Mar 26, 2021
Make SimpleReactiveMongoRepository#saveAll(Publisher<S>) return the saved entity references instead of the original references. Closes spring-projects#3609
petitcl
added a commit
to petitcl/spring-data-mongodb
that referenced
this issue
Mar 26, 2021
Make SimpleReactiveMongoRepository#saveAll(Publisher<S>) return the saved entity references instead of the original references. Closes spring-projects#3609
petitcl
added a commit
to petitcl/spring-data-mongodb
that referenced
this issue
Mar 26, 2021
Make SimpleReactiveMongoRepository#saveAll(Publisher<S>) return the saved entity references instead of the original references. Closes spring-projects#3609
petitcl
added a commit
to petitcl/spring-data-mongodb
that referenced
this issue
Mar 26, 2021
Make SimpleReactiveMongoRepository#saveAll(Publisher<S>) return the saved entity references instead of the original references. Closes spring-projects#3609
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using the
Flux<S> saveAll(Publisher<S> entityStream)
method from theSimpleReactiveMongoRepository
class, the returned entities do not have their@Id
annotated property populated, in the case where the annotated field is immutable.The
@Id
annotated property should obviously be populated with the ObjectId generated by mongodb.This bug does not affect
Flux<S> saveAll(Iterable<S> entities)
norFlux<S> insert(Publisher<S> entities)
. It only occurs if the@Id
property is immutable (ie:final
and no setter).I was able to reproduce the bug on the following versions:
3.1.6
, spring-data-commons2.4.6
3.0.7
, spring-data-commons2.3.7
2.2.12
, spring-data-commons2.2.12
Here a sample repository to reproduce this bug: petitcl/spring-data-mongodb-sample-1. This sample shows that the bug occurs for an immutable entity but not for a mutable entity.
After looking at the code of
SimpleReactiveMongoRepository
in version2.4.4
, it seems to be due to the fact that the original entity reference is returned, instead of the entity returned by the underlyingMongoOperations
.This works if the entity is mutable, because the entity reference will be updated with the new id, but it does not work if the entity is immutable, as it would require a new reference with the populated id.
Current Code:
What I assume it should look like:
If you validate that this is indeed a bug, I can probably submit a PR to fix it.
The text was updated successfully, but these errors were encountered: