I have a domain class Person
annotated with Lombok @Value
thus marking it as immutable, having has 3 fields.
In my service layer, I am making a call to the repository to check if the the person exists or not.
If it does exist, I need to take the Person
object from the database and update the money
field.
Since it is immutable, this cannot be done. I was reading some articles and came across that this can be done using builder pattern.
I will probably need to create a updatePerson()
in my Person
class but not sure how to do it. Or do I need to do something else ?
Person.java
:
@Value
@Builder
public class Person {
private final UUID id;
private final String job;
private final BigDecimal money;
}
I am using Java 15.
money
should not befinal
(so it can be updated). Changing @Value to @Data should create the setter and getter formoney
, and only a getter for the other attributes that are stillfinal
. – Crosspiece