Patch Object

The framework supports incremental updates on numeric fields using special suffixes in the patch object.

Suffix Mapping

For example, to increase a user's score by a certain amount without first reading the original value, you can use a field like scoreAe (short for Add/Extend).

public class UserPatch extends UserEntity {
    private Integer scoreAe;
}

UserEntity userPatch = UserPatch.builder().id(1).valid(true).scoreAe(20).build();
userDataAccess.patch(userPatch);
// SQL: UPDATE t_user SET valid = ?, score = score + ? WHERE id = ?

Annotation Mapping

Use @Clause to define a custom condition:

public class UserPatch extends UserEntity {
    @Clause("score = score + ?")
    private Integer scoreAe;
}

Last updated

Was this helpful?