<?xml version="1.0" encoding="UTF-8" standalone="yes"?><oembed><version><![CDATA[1.0]]></version><provider_name><![CDATA[Craig Andrews]]></provider_name><provider_url><![CDATA[http://candrews.integralblue.com]]></provider_url><author_name><![CDATA[Craig Andrews]]></author_name><author_url><![CDATA[http://candrews.integralblue.com/author/candrews/]]></author_url><title><![CDATA[EhCache implementation of OpenJPA caching]]></title><type><![CDATA[link]]></type><html><![CDATA[I usually use <a href="http://www.hibernate.org/">Hibernate</a>, which supports a <a href="http://www.hibernate.org/hib_docs/reference/en/html/performance-cache.html">number of caching implementations</a> (such as EhCache, oscache, JBoss, etc). My most recent project had a dependency on <a href="http://www.elasticpath.com/">a product</a> which has a dependency on <a href="http://http://openjpa.apache.org/">OpenJPA</a>, and OpenJPA only has it's own built in implementations of a <a href="http://openjpa.apache.org/builds/1.2.0/apache-openjpa-1.2.0/docs/manual/ref_guide_caching.html#ref_guide_cache_query">query cache</a> and a <a href="http://openjpa.apache.org/builds/1.2.0/apache-openjpa-1.2.0/docs/manual/ref_guide_caching.html#ref_guide_cache_conf">data cache</a>. I like to have one caching implementation in my project, so having two (OpenJPA's for itself, and EhCache for everything else) annoyed me. So I had to fix it.

I started with <a href="http://mail-archives.apache.org/mod_mbox/openjpa-users/200803.mbox/%3C16378911.post@talk.nabble.com%3E">Pinaki Poddar's implementation of a Coherence provided OpenJPA data cache</a>. I changed it to use EhCache, adjusted the unit tests, and then added a query cache implementation. To use it, add a dependency on the openjpa-ehcache, then set OpenJPA's "openjpa.QueryCache" to "ehcache" and "openjpa.DataCacheManager" to ehcache. That's it!

The code can be compiled with Maven. Simply run "mvn install".

My code, like EhCache and OpenJPA, is licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache Public License 2.0</a>. <a href="http://candrews.integralblue.com/wp-content/uploads/2009/03/openjpa-ehcachetar.gz">Get it here</a>.]]></html></oembed>