Skip to content

Auditing broken for entities using optimistic locking via version properties [DATAMONGO-2139] #3008

@spring-projects-issues

Description

@spring-projects-issues

iqjumps opened DATAMONGO-2139 and commented

Entity class A has Id, version and auditing fields:

 

@Data
@Document
public class A {
  @Id String id;
  @Version Long version;
  @CreatedDate Date createdAt;
  @LastModifiedDate Date lastModifiedAt;
}

 

and I tried to save new A,

ARepository.save(new A());

but result document stored in mongodb doesn't have createdAt field. (only lastModifiedAt field exists)

 

In doInsert() in MongoTemplate, it set 0 to version field

T toSave = entity.initializeVersionProperty();

and then IsNewAwareAuditingHandler checks whether entity is new using IsNewStrategy,

but version field is already set to 0, so it's not new object.

So CreatedXX fields are not touched.

 

I don't know it's intended


Affects: 2.1.2 (Lovelace SR2)

Issue Links:

  • DATAMONGO-2128 DuplicateKeyException since upgraded to SpringBoot 2.1 when using Optimistic Locking
    ("is duplicated by")
  • DATAMONGO-2127 @CreatedDate and @CreatedBy are not set anymore after upgrading Spring Boot to 2.1.0
    ("is duplicated by")
  • DATAMONGO-2179 CreatedDate is null for entities using optimistic locking via version property when saving/inserting in batch
    ("is duplicated by")
  • DATAMONGO-2150 Auditing broken for entities using optimistic locking via version properties in reactive mongo

Backported to: 2.1.3 (Lovelace SR3)

0 votes, 7 watchers

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions