Mongotemplate.updateFirst()不会更新@LastModifiedDate [英] Mongotemplate.updateFirst() doesn't update @LastModifiedDate
问题描述
我正在使用基于注释的配置.
I'm using annotation based configuration.
@Configuration
@Profile("default")
@ComponentScan(basePackages = "com.*")
@EnableMongoRepositories
@EnableMongoAuditing
public class ApplicationDataConfig ....
我还对类型为org.joda.time.DateTime
的字段设置了@LastModifiedDate
,@CreatedDate
批注.当我使用
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(实体)
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()
org.springframework.data.mongodb.core.MongoTemplate.updateFirst()/updateMulti()
上次更新时间未更新.有人知道什么地方可能出问题了吗?我正在使用spring-data-mongodb1.8.3
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
推荐答案
我发现@Id字段在save()时需要为空 仅用于@CreatedDate和@CreatedBy批注.这 @LastModifiedDate和@LastModifiedBy字段不管 @Id字段是否已初始化.
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.
请参阅此处: https://stackoverflow.com/a/31018339/5939750
这篇关于Mongotemplate.updateFirst()不会更新@LastModifiedDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!