Best Spring / Hibernate configuration for ever-changing tables

I am currently using Spring + Hibernate + MySQL for a project I am working on. I realized that I have several tables that never change. They are static, there can be no insertions or updates in these tables, and therefore they can be considered immutable. All calls to these tables are done using lazy loading (can be called) collections of entities and hql queries.

I am wondering in which case is best suited for working with such a scenario. I have the basics in place, read-only ehcache, query caching and read-only transactions (does this do anything for Mysql?). What else can I look at? What ISOLATION modes, PREPAGATION modes are best? Should I look at other caching solutions? Or should I just get rid of all this and just load the data once in a row of hash cards (this, I hope, will be the last resort)?

Another possible (far-fetched?) Solution would be to have some database in / without transactional memory and connect sleep mode to it. Are there such db mechanisms?

I would appreciate any guidance you guys have had!

+6
java performance spring mysql hibernate
source share
5 answers

Configure second-level cahce for all objects (check the sleep mode documentation for various configuration / mapping information for caching), configure the request cache and mark them as immutable in read-only mapping / use sessions, this will cause the sleep mode to not be Check for modifications to these objects when performing "transactional write" and cleaning the session.

This is a very common scenario, and that’s all you need to do. You do not have to deal with deploying your own memory cache cache (second-level caches, such as echache, offer you several alternatives for storage), what the second-level cache will do for you. A transaction less access to the database does not offer you anything, performance is wise, so I would not worry about it and let hibernate handle it.

+2
source share

I dealt with similar things before, with tables of data enumerations that do not change, and, frankly, the simplest thing was to simply set up the tables to load and do with it. The optimization you can get from everything else is relatively small if the tables are not very large. Not to be neglected, but your time is probably better spent optimizing another part of your system.

However, if your tables are especially large, you may want to consider another method of dereferencing the data that they contain; if the table data is large and really never changes, you can consider a different way to populate the object tree, besides using Hibernate; it may be useful to simply create a class for enumeration and manage the link of this link yourself (i.e. without sleep mode).

+2
source share

I believe read-only transactions are Hibernate optimizations. If Hibernate knows that it will not need to figure out that you have changed something in the objects, it may refuse a bunch of steps (modification of the CGLib classes?)

+1
source share

I think most of your other questions have been answered. However, as isolation levels go, if your table has never been inserted or updated, you can use the READ_UNCOMMITTED isolation level, which allows dirty reads, irreproducible reads, and phantom reads. 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 release row locks the most and give you better performance, at least until commit.

+1
source share

In my experience, these tables need to be removed from the database and converted to enumerations or something else. Not because of performance, but for maintainability. Believe it or not, changing the code (again in my experience) is a simpler and cut out operation than writing scripts to modify data in a production database. Especially if you do not necessarily control the database yourself; doubly, especially if your company does not even control it.

-2
source share

All Articles