Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Spring/Hibernate configuration for never changing tables

I'm currently using Spring+Hibernate+MySQL for a project I'm working on. I realized that a have quite a few tables which never change. They are static, no insert or updates can ever occur on these tables, and so can be considered immutable. All accesses to these tables are via lazy loading (can be made eager) of entity collections and hql queries.

I'm wondering for such a case what would be the best approach performance-wise for handling such a scenario. I have the basics in place, read only ehcache, query caching and the transactions set to read-only (does this do anything at all for Mysql?). What other things can I look at? Which ISOLATION modes, PROPAGATION modes are best? Should I be looking at other caching solutions? Or should I simply do away with all this and just load the data once into a series of hashmaps (this hopefully will be a last resort)?

Another possible (far-fetched?) solution would be to have some in-memory/no-transaction database and have hibernate connect to it. Do such db engines exist?

I'd appreciate any pointers, experience you guys have had!

like image 603
Il-Bhima Avatar asked May 26 '09 22:05

Il-Bhima


People also ask

Why we need second level cache in Hibernate?

Why Is a Second-Level Cache Important for Hibernate? A second-level cache improves application performance with regard to persistence for all sessions created with the same session factory.

How to disable 2nd level cache in Hibernate?

To disable second-level caching (say for debugging purposes), we just set the hibernate. cache. use_second_level_cache property to false.

What is query caching in Hibernate?

Advertisements. Caching is a mechanism to enhance the performance of a system. It is a buffer memorythat lies between the application and the database. Cache memory stores recently used data items in order to reduce the number of database hits as much as possible.


1 Answers

Setup second level cahce's for all the entities ( check hibernate documentation for various configuration/mapping details for caching) ,configure query cache and mark them as immutable in the mapping / use read-only sessions, this would make hibernate not check for modifications for these entities when doing "transactional write-behind" and session flushing.

This is a very common scenario and this is all you should have to do . You shouldn't have to deal with rolling out your own in memory hashmap cache ( second level caches like echache offer you several storage alternative), that what second level cache would do for you. Transaction less DB access doesn't offer you anything , performance wise , so I wouldn't worry about it and let hibernate deal with it .

like image 123
Surya Avatar answered Sep 28 '22 23:09

Surya