Skip to content

Update using $inc does not work if @Version is present in the entity #4918

Closed
@symphony-enrico

Description

@symphony-enrico

Given following entity:

@Document("entitlementJobExecution")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class EntitlementJobExecution {
  @Id
  private ObjectId id;

  private Long executedLines;
  private Long successfullyExecutedLines;

  @Version
  private Long version;

}

and the following repository:

@Repository
public interface EntitlementJobExecutionRepository extends MongoRepository<EntitlementJobExecution, ObjectId> {
  @Update("{ '$inc' : { 'executedLines' : ?1, 'successfullyExecutedLines' : ?2 } }")
  void findAndIncrementExecutedLinesAndSuccessfullyExecutedLinesById(
    ObjectId id,
    int executedLines,
    int successfullyExecutedLines
  );
}

The query does not work as expected. No error is reported, but it generates:

o.s.data.mongodb.core.MongoTemplate      : Calling update using query: { "_id" : { "$oid" : "67cf20da7b8c784443a05eb5"}} and update: { "$inc" : { "version" : 1}} in collection: entitlementJobExecution

Thus, executedLines and successfullyExecutedLines are not updated.
If I remove @Version from entity, it works as expected.

Thanks

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions