Mongotemplate.updateFirst() doesn't update @LastModifiedDate

◇◆丶佛笑我妖孽 提交于 2020-01-12 10:08:49

问题


I'm using annotation based configuration.

@Configuration
@Profile("default")
@ComponentScan(basePackages = "com.*")
@EnableMongoRepositories
@EnableMongoAuditing
public class ApplicationDataConfig ....

And I also have @LastModifiedDate, @CreatedDate annotation set on fields of type org.joda.time.DateTime. When I use

org.springframework.data.mongodb.repository.MongoRepository.save(entity)

both the audit fields are updated just fine. But when I use

org.springframework.data.mongodb.core.MongoTemplate.updateFirst()/updateMulti()

the lastupdated time is not being updated. Does anybody have a clue of what could be wrong? I'm using spring-data-mongodb1.8.3


回答1:


I found that the @Id field needed to be null at the time of save() only for the @CreatedDate and @CreatedBy annotations. The @LastModifiedDate and @LastModifiedBy fields worked regardless of whether the @Id field was initialized or not.

See here: https://stackoverflow.com/a/31018339/5939750



来源:https://stackoverflow.com/questions/39296277/mongotemplate-updatefirst-doesnt-update-lastmodifieddate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!