How to have version and audit information inside a nested object in springboot-MongoDB?

Viewed 182

I have a version and auditing info in the @document class and it works fine.

Note:using this org.springframework.data.annotation.Version;

EmployeeModelDTO.java

@Getter
@Setter
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@NoArgsConstructor
@AllArgsConstructor
@Document(collection = "unt-employee")
public class EmployeeModelDTO implements Serializable {
    private static final long serialVersionUID = 1L;
    private String type;
    @Field("group")
    private GroupDTO groupDTO;
    
    @Id
    @JsonAlias("id")
    String id;

    @Version
    Integer schema_version;

    @LastModifiedDate
    LocalDateTime updatedDateTime;

    @CreatedDate
    LocalDateTime createdDateTime;
}

But if i try to put it inside a nested objects it is not getting inserted into mongo db I need to have it inside GroupDTO.java

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class GroupDTO{

    @Id
    @JsonAlias("id")
    String id;

    @Version
    Integer schema_version;

    @LastModifiedDate
    LocalDateTime updatedDateTime;

    @CreatedDate
    LocalDateTime createdDateTime;

}

So if I put the version and other info inside this class, it is not getting populated. Can any one let me know if having the version and other info inside the nested class is possible ?

0 Answers
Related