Hi there,
a common problem of low performance are repeated queries which give the same result each time. For example:
Query q = session
.createQuery("from artikel in class Artikel where lower(artikel.isbn) = ?");
q.setString(0,_isbn);
...
return artikel.getId();
Insted of repeating the same query every time an getting the same result from database, you can simply cache it. Do not forget to set a cache region for this specific query. The following example code caches the result:
Query q = session
.createQuery("from artikel in class Artikel where lower(artikel.isbn) = ?")
.setCacheable(true)
.setCacheRegion("getArtikelId_"+_isbn);
As you can see we use method name and query parameter to cache this result automatically by hibernate. Next time your application is looking for the same ISBN, the result is only fetched from hibernates cache. If you like refetch it directly from database, simply add an additional value to cacheregion. My suggestion is to use a timestamp as addition string in those cases.
This improvement has speed up our repeating application calls up to factor 1.000 %, so it is really worth to try it :-))
Andreas Bednarz
id-on GmbH, Hannover Germany
bednarz((@))id-on.de
www.id-on.de