2nd level cache (read this one, not the previous)
jamesjmp Apr 4, 2008 1:34 PMhi,
(Please reply to this one, in the previous I forgot to activate Notify me via e-mail of any replies)
I want to add second level cache to my seam application (SEAM 2.0.1.GA, JBoss 4.2.2). After reading up some docs there are some config issues I´m not sure how to tackle in Seam.
According to my needs I have finally chosen OSCache. In my persistence.xml I´ve set my provider class
<property name="hibernate.cache.provider_class" value="com.opensymphony.oscache.hibernate.OSCacheProvider"/>
In the entities I want to cache I´ve used org.hibernate.annotations.Cache defining the strategy and include params.For now, I´m not interested in defining regions names. for instance:
@Entity @Cache (usage=CacheConcurrencyStrategy.READ_WRITE, include="non-lazy") @Table(name = "CFG_CURRENCY", catalog = "prisk", uniqueConstraints = @UniqueConstraint(columnNames = "currency_iso")) public class CfgCurrency implements java.io.Serializable {
But, I also want to cache some of my seam-gened based queries that look this way:
I´ve read up about the cacheable param to be set to a query.(My seam-gened queries are org.jboss.seam.framework.EntityQuery) I´ve tried with the javax.persistence.QueryHint annotation:
@Name("cfgCurrencyList") @QueryHint(name="org.hibernate.cacheable",value="true") public class CfgCurrencyList extends EntityQuery {
With that I have this compilation error:
annotation type not applicable to this kind of declaration
So then I´ve tried this 2 ways:
//1st way, in CfgCurrencyList.java @Override public void setHints(Map arg0) { System.out.println("cfgCurrencyList - setHints!!!"); Map region = new TreeMap(); region.put("org.hibernate.cacheable", "true"); //IN THE FUTURE IF I DEFINE REGION, I WOULD USE THIS // region.put("org.hibernate.cacheRegion", "/CfgCurrencyListQuery"); super.setHints(region); } //2nd way: setting the hints from outside * query.setHint("org.hibernate.cacheable", "true")
This compiles, but I´m not sure if that´s the proper way to do this because the trace cfgCurrencyList - setHints!!! is never displayed and I´m using that Query. I think my app is not taking into account it.
am I doing it correctly? thanks in advance!.