I have some tables for which I have no reason to ever update from within the application, so I would like to prevent it from happening even accidentally by a bug somewhere else.
I see the @Immutable
annotation, but it looks like that will still allow insertions and deletions. I'd like to full on treat the whole table (not just each entity) as written in stone. Is there an easy way to accomplish this? Or do I misunderstand the documentation on @Immutable
?
If an example is needed, lets say that there is a table with MONTH
table, and a Month
entity, and a APPOINTMENT
table with a Appointment
entity associated. I would never want to delete or insert a row into month.
Generally, we use @Transactional(readOnly = true) for search or retrieval operation to make sure we can only perform the read-only operation. We can override readOnly behavior using @Modifying annotation.
READ_WRITE key and the readOnlyDataSource using the DataSourceType. READ_ONLY key. So, when executing a read-write @Transactional method, the readWriteDataSource will be used while when executing a @Transactional(readOnly = true) method, the readOnlyDataSource will be used instead.
It's good practice to define the @Transactional(readOnly = true) annotation at the class level and only override it for read-write methods. This way, we can make sure that read-only methods are executed by default on the Replica nodes.
Have you tried read only caching strategy:
If your application needs to read, but not modify, instances of a persistent class, a read-only cache can be used. This is the simplest and optimal performing strategy. It is even safe for use in a cluster.
From: 19.2.2. Strategy: read only
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With