I am trying to enable caching for Hibernate.
I have this in my persistence.xml:
Code:
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.jbc2.MultiplexedJBossCacheRegionFactory" />
And I put this in my persisted object:
Code:
@org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.TRANSACTIONAL)
When I access a page that displays the object, I see in the console all the SQL queries performed.
When I reload the page I still see queries even though they are not all the same (checked with diff, most are the same, but not all).
Is this normal behavior ?
I expected that the 2nd time the page is loaded no SQL would be displayed in the console.
If this isn't normal behavior, what should I change in order to use the cache ?
How can I make sure the cache is used and the DB is not accessed at all ?
Ideally I would load in memory a bunch of top level objects that have a lot of dependencies (including the dependencies) so when the users browse/edit pages related to a certain object or its dependencies, the cache is used instead of accessing the DB.
Thx.