首页  编辑  

SpringBoot/JPA/MongoDB @CreatedDate 注解不生效

Tags: /Java/   Date Created:
SpringBoot JPA中,MongoDB,实体类定义:
@Document
public class Demo {
  @Id private final String id;
  private String name;
  @CreatedDate
  private Date creationDate;
  @LastModifiedDate
  private Date updateDate;
}

@CreatedDate注解不生效,但是@LastModifiedDate运行良好。

解决方法: Spring Data Couchbase - Reference Documentation
1. 必须在配置类,启用 @EnableMongoAuditing
2. 必须定义 @Version 字段:
@Document
public class Demo {
  @Id private final String id;
  private String name;
  @CreatedDate
  private Date creationDate;
  @LastModifiedDate
  private Date updateDate;
  @Version
  private long version;
}