Archive | 4:48 pm

Hibernate Query Cache

7 Apr

Hibernate provides sophisticated caching mechanisms to improve the performance. Apart from
First-level, Second-Level and query cache, Hibernate can be configured to make use of some open source cache solutions like EHCache or JBoss Cache etc.

If your Hibernate query yields huge but similar results every time it is executed, it is a good idea to cache the results in hibernate to improve the performance. This could be achieved by first enable the hibernate query cache in the hibernate configuration
in properties file

hibernate.cache.use_query_cache true

or xml configuration file like

<property name="hibernate.cache.use_query_cache">true</property>

and while executing the query specify the cacheability like this

sess.createQuery("from.......")
    .setCacheable(true)
    .list();

SQLGrammarException could not fetch initial value for increment generator

7 Apr

In the earlier versions of Hibernate, may be hibernate 2.x, if you use increment generator on a new table then you might get this error. If you really need to use the increment generator on the new table then you need to create a dummy row on that table.
This issue is not present in the current version of hibernate i.e. Hibernate 3.x

Follow

Get every new post delivered to your Inbox.