I have few tables like Country,state city which has static data. User do not enter any data in this data. I create pojo for Country, State, City. There are few pojo which has mapping with static data. My requirement is that whenever any request comes to Hibernate for Country (21), it do not hit database but return data from cache . Is this possible in Hibernate. I need few pointers and your views to implement caching in my project. I am using hibernate annotations.
Share
Yes, this is possible using the Second Level Cache and this kind of Entities (read-only) are the perfect candidates for caching (they are the easiest to manage). You’ll need to:
hibernate.cache.use_second_level_cacheproperty totruein your configurationhibernate.cache.provider_classproperty accordinglyread-onlystrategy)@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)to your entitiesReferences
More Resources