I have a case where one particular table is automatically generated by database triggers. I've mapped an entity to it, and I want to be able to retrieve these entities. But I don't want the application to be able to make any updates or insert any records.
What's the best practice for this in JPA2? I could label all the columns with updatable=false (and labelling them insertable=false might work as well, but I could see that not preventing inserting blank records), and I can make sure that there are no setter methods. But is there a better/simpler approach?
(I'm pretty new to JPA, so I could be missing something obvious).
Setting each column to insertable or updateable =false is a very bad idea, these are only for columns that should not be written not rows.
In general the best solution is to not change your objects, if they are read-only then you should not change them, and they will not be updated.
If you wish to find bugs in your code that is incorrectly changing objects the best solution is probably to use events, a to pre/postPersist/Update events should work for this, just throw an error if any of these events is raised.
You could keep these events in development, and them remove them in production once you know your code is correct.