javaspringspring-dataspring-data-jdbc

Cannot persist entity


I have been getting this exception. What would be the best way to implement versioning in an entity so that I can persist my entity? I would like to avoid unnecessary setters if possible

java.lang.IllegalStateException: Cannot set property version because no setter, no wither and it's not part of the persistence constructor public com.ezycorp.eve.domain.Merchant(java.lang.String,java.lang.String,java.lang.Integer,java.lang.String,java.lang.String,java.lang.String)

This is my entity

@Table("merchant")
public class Merchant {

    @Id
    private final MerchantId id;

    private final String name;

    private final MerchantKeyId merchantKeyId;

    private final String username;

    private final String password;

    private final String webhookUrl;

    @Version
    private final int version=0;


    @PersistenceCreator
    public Merchant(String id, String name, Integer merchantKeyId, String username, String password, String webhookUrl) {
        this.id = new MerchantId(id);
        this.name = name;
        this.merchantKeyId = new MerchantKeyId(merchantKeyId);
        this.username = username;
        this.password = password;
        this.webhookUrl = webhookUrl;
    }
}

...omitted getters

Solution

  • The error message pretty much tells you your options: