i want disable merge in jpa repository. It should only be possible to create new records and prohibit updating old ones.
So, how to disable the update of records for the repository if i extends from JpaRepository?
i want disable merge in jpa repository. It should only be possible to create new records and prohibit updating old ones.
So, how to disable the update of records for the repository if i extends from JpaRepository?
Making your entity immutable can stop changes happening to managed entities and as a result no changes will be propagated within the transaction.
However it does not stop hibernate updating the database record, if you passed immutable record with id assigned and it already exists in db.
So I think you can look into @PreUpdate entity listener and throw exception. So if someone tries to update, it will throw exception and update will not happen.
But the best way is to create service which hides the repository and
Service does a find before save to avoid second point
Make the entity immutable to make sure first point.
What you need is basically an immutable entity, remove setters from your entity and use builders to create new entities.