Spring 审计注释适用于顶级(processStatus)文档,但不适用于子文档(stepsDetails)。
@Document(collection = "processStatus")
public class ProcessStatus {
@Id
private ObjectId id;
@Field("steps")
private Collection<StepDetails> steps;
@Version
private Long version;
@CreatedBy
private String createdBy;
@CreatedDate
private Date createdDate;
@LastModifiedDate
private Date lastModifiedDate;
@LastModifiedBy
private String lastModifiedBy;
... //not including getter/setters
}
子文档
@Document(collection="stepsDetails")
public class StepDetails{
@Id
private ObjectId id;
@Field("name")
private String step;
@Field("status")
private String status;
@Version
private Long version;
@CreatedDate
private Date createdDate;
@LastModifiedDate
private Date lastModifiedDate;
}
我在配置类上添加了@EnableMongoAuditing。当我在 mongo 数据库中插入 processStatus 文档时,我发现 StepDetails 中的审核字段未填充。我需要让它工作,因为各种进程会多次更新stepDetails。
子文档支持这些注释吗??有人知道我怎样才能实现这个目标吗?
最佳答案
也遇到了同样的问题。您可以让域对象实现 Auditable 接口(interface)及其方法。您还可以使用 RepositoryEventHandler 手动设置子文档的字段。
https://docs.spring.io/spring-data/mongodb/docs/1.10.7.RELEASE/reference/html/#auditing
关于java - Spring Data 审核注释 @creationDate 和 @LastModifiedDate 不适用于 mongo @EnableMongoAuditing 的子文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43498859/