为什么Spring Data MongoDB不公开事件用于update ...(...)方法? [英] Why does Spring Data MongoDB not expose events for update…(…) methods?
问题描述
mongoOperations 的更新似乎不会在 AbstractMongoEventListener 中触发事件.
It appears that the update for mongoOperations do not trigger the events in AbstractMongoEventListener.
This post indicates that was at least the case in Nov 2014
目前是否有任何方法可以监听更新事件,如下所示?如果是这样的话,这似乎是一个很大的遗漏.
Is there currently any way to listen to update events like below? This seems to be quite a big omission if it is the case.
MongoTemplate.updateMulti()
谢谢!
推荐答案
这不是疏忽.事件至少是围绕域对象或文档的生命周期设计的,这意味着它们通常包含您感兴趣的域对象的实例.
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.
另一方面,更新是完全在数据库中处理的.因此,没有文档,甚至没有在MongoTemplate
中处理的域对象.考虑这种基本相同的方式,即仅针对首先加载到持久性上下文中的实体触发JPA @EntityListener
的方式,而不会因为数据库中查询的执行而在执行查询时触发JPA @EntityListener
的方式.
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 @EntityListener
s 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.
这篇关于为什么Spring Data MongoDB不公开事件用于update ...(...)方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!