Is it possible to consider a table as read only in sleep mode?

I have several tables for which I have no reason to ever update from the application, so I would like to prevent an accidental occurrence of an error elsewhere.

I see the @Immutable annotation, but it looks like it will still allow insert and delete. I would like to completely process the entire table (and not just each entity), as it is written on the stone. Is there an easy way to do this? Or am I misunderstanding the @Immutable documentation?

If an example is required, let's say that there is a table with a table MONTH and a Month entity and an APPOINTMENT table with an APPOINTMENT binding. I would never want to delete or insert a row per month.

+6
source share
2 answers

Have you tried read-only caching strategy:

If your application needs to read, but not modify , instances of the constant class, you can use read-only cache access. This is the simplest and optimal execution strategy. It is even safe to use in a cluster.

From: 19.2.2. Strategy: Read Only

+3
source

One way is to use READ_ONLY transactions by putting @Transactional(readOnly=true) in the method.

http://www.codeinstructions.com/2009/04/read-only-transactions-with-spring-and.html .

Another method. Regarding isolation levels, if your table has never been inserted or updated, you can use the READ_UNCOMMITTED isolation level, which allows you to read dirty reads, irreproducible readings, and phantom. However, none of this matters since the data never changes.

You can see the different isolation levels and the effects of each in spring javadocs ( http://docs.huihoo.com/javadoc/spring/2.5/org/springframework/transaction/annotation/Isolation.html )

This will free the line locks the most and give you better performance, at least until the lock goes

+1
source

Source: https://habr.com/ru/post/912085/


All Articles