What is the proper way to make an Entity read-only with JPA ? I wish my database table to never be modified at all programmatically.
I think I understand that I should lock my objects with LockModeType.READ. Is it possible to use an annotation to make my entities directly locked after retrieval from the database ? Or do I have to mess around and override my generic DAO for that specific entity ?
A solution is to use field based annotation, to declare your fields as
protectedand to propose only public getter. Doing so, your objects can not be altered.(This solution is not entity specific, it is just a way to build immutable objects)