Hi Arjun, >> I am trying to cache the query results generated and later on use the >> results from the cache instead of touching the database.
I think if you enable the querycache properly then openJPA has to do it for you. Check this link which explains the same: http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_cache_query To enable query cache add the following in the persistence.xml: <property name="openjpa.DataCache" value="true"/> <property name="openjpa.RemoteCommitProvider" value="sjvm"/> <property name="openjpa.QueryCache" value="true"/> I hope that answers your question. If not, and you are still looking to get a key then may be the following will help: CacheMap cmap = ((ConcurrentQueryCache)(OpenJPAPersistence.cast(EntityManager.getEntityManagerFactory()).getQueryResultCache().getDelegate())).getCacheMap(); The above will give you a map and MAY be cmap.keySet() or cmap.getPinnedKeys() should give you set of keys. Regards, Ravi. Hi All, I am trying to cache the query results generated and later on use the results from the cache instead of touching the database. This is what I am doing to put/get the values from the cache. ********** final String queryString = "select P from Parents P"; Query query = getEntityManager().createQuery(queryString); OpenJPAEntityManagerFactory oemf = OpenJPAPersistence.cast(EntityManagerHelper.getEmf()); QueryResultCacheImpl queryResultCache = (QueryResultCacheImpl)oemf.getQueryResultCache(); QueryCache qCache = queryResultCache.getDelegate(); qCache.put(key, (QueryResult)query.getResultList()); // Put into the cache QueryResult cachedItems = qCache.get(key); // Get from the cache ********** The thing I don't understand is how do I get the QueryKey (Referred to as key here in my code) ? I tried doing this QueryKey key = QueryKey.newInstance(q); but the q here in this line of code is supposed to be of type org.apache.openjpa.kernel.Query? Can anybody help me with this please? Thanks. -- View this message in context: http://n2.nabble.com/0penJPA-QueryCaching-tp2653013p2661607.html Sent from the OpenJPA Developers mailing list archive at Nabble.com.
