-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
@EnableMongoAuditing
does not play well with MongoRepository#insert
#4902
Comments
This is due to a mix of intentions vs. is-new detection. While one could argue that exposing the Ideally, the repository should determine itself whether an entity is new or whether it exists. However, we do not have any means of propagating the is-new aspect into callbacks and I doubt we will ever have because that contextual information is not part of the interface. |
@EnableMongoAuditing
does not play well with MongoRepository#insert
The two only options you have are:
|
Hi @mp911de , thx for your time and your suggestions.
There are scenarios where "the isNew()" logic just fits better in business/service code instead of entity/model code. I work with a lot of generated (model) code - extending them with logic (or an interface) is sometimes easy work and sometimes hard work.
I like your 2) suggestion! Thank you very much ! |
Hello,
when pre-populating the @id field before doing a
MongoRepository#insert
, the auditing functionality will only set the@LastModifiedBy
field and ignore the@CreatedBy
field.I expect the
MongoRepository#insert
method to force a isNew=true flag/strategy throughout the whole persist attempt so that the settingEnableMongoAuditing#modifyOnCreate() default true
can kick in.My current fix is to add a custom EntityCallback ensuring the setting of
CreatedBy
. This EntityCallback is getting executed afterorg.springframework.data.mongodb.core.mapping.eventAuditingEntityCallback
The text was updated successfully, but these errors were encountered: