Why does Spring Data MongoDB not expose events for update…(…) methods?

后端 未结 3 1661
情话喂你
情话喂你 2021-01-07 09:37

It appears that the update for mongoOperations do not trigger the events in AbstractMongoEventListener.

This post indicates that wa

3条回答
  •  半阙折子戏
    2021-01-07 10:01

    This is no oversight. Events are designed around the lifecycle of a domain object or a document at least, which means they usually contain an instance of the domain object you're interested in.

    Updates on the other hand are completely handled in the database. So there are no documents or even domain objects handled in MongoTemplate. Consider this basically the same way JPA @EntityListeners are only triggered for entities that are loaded into the persistence context in the first place, but not triggered when a query is executed as the execution of the query is happening in the database.

提交回复
热议问题