I'm looking for a way to prevent objects from updating with spring-data. I've found some topics about this, but none of them have a solution.
I have an object, that can be created and read. That's it. I do not want to support modifications/updates. I manage/generate the database-id myself.
I would love to use org.springframework.data.repository.Repository interface (or JpaRepository/CrudRepository if I can somehow change the <S extends T> S save(S entity); logic to prevent update), because I love the clean findBy... interface notations.
The best solution I've found so far is to implement Persistable and overwrite the isNew(…) to always return true. But that's just crappy, because the object is not "new" if it's read-only.
Is there any clean way to achieve this?
updatable = falseto every attribute of the entity. Then, calls toupdatewill be ignored because the JPA provider will not detect any changes to persist.Fooand its associated repositoryFooRepository. Do you wantFooRepositoryto have noCUD(create, update, delete) methods (that is, only read methods), or do you want the methods to be there but have no effect when called? It will be useful if you can add the desired definition (what methods you want) forFooRepositoryto the question.