You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by nasseria1 <na...@gmail.com> on 2010/10/20 15:32:03 UTC

Setting entity cach on persistence.xml or @DataCache annotation?

Dear All,

We are using OpenJPA 1.2 on glassfish. We use entity caching to improve our
application performance. 
As you may know, there are two options to set cache settings in an
OpenJPA-based application: At persistence-level that use persistence.xml, we
just set DataCache there to enable entity caching in the whole application:
<property name="openjpa.DataCache" value="true"/>

and at entity-level that requires @DataCache annotation:

@DataCache(enabled=true)
public class OpenJPACacheTest { ... }

The first question is which method has the highest priority? Using xml or
annotation? Is annotation overrides cache settings in persistence.xml? For
e.g. if I enable cache on persistence.xml and disable it on entity level
using enabled=false, which setting is applied finally?

And the second question is about setting entity cache timeout in
persistence.xml. I found out setting cache time-out to evict an entity using
DataCache annotation is doable after a special time out expiration. We can
use timeout attribute from @DataCache annotation:

@DataCache(timeout=10000)
public class OpenJPACacheTest { ... }

But for now, can I set entity cache timeout on persistence.xml? And if the
answer is yes, which method has the highest priority again?

Thanks for any tips,
Nasseria
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Setting-entity-cach-on-persistence-xml-or-DataCache-annotation-tp5654852p5654852.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Re: Setting entity cach on persistence.xml or @DataCache annotation?

Posted by Michael Dick <mi...@gmail.com>.
Hi,

The persistence.xml setting enables the cache for all entities in your
persistence unit. You can then exclude specific entities by using the
DataCache annotation and setting enabled=false. Any entity which does not
have an @DataCache annotation will be cached by default.

To put it another way. The settings in persistence.xml is required to enable
the cache. The annotations can be used to configure which entities are
included in the cache.

In addition to the openjpa.DataCache property you'll need to add this one :
<property name="openjpa.RemoteCommitProvider" value="sjvm"/>

The remote commit provider, ostensibly, allows for synchronization between
datacaches on multiple JVMs, but generally you'll want to stick with the
default (single JVM).

The OpenJPA manual covers datacache configuration here :
http://openjpa.apache.org/builds/1.2.2/apache-openjpa-1.2.2/docs/manual/manual.html#ref_guide_cache_conf.


Regarding your second question, the eviction timeout is specified for each
entity type. As far as I know there's no way to configure it in
persistence.xml, so you'll have to set it in the annotation.

Hope this helps,
-mike


On Wed, Oct 20, 2010 at 8:32 AM, nasseria1 <na...@gmail.com> wrote:

>
> Dear All,
>
> We are using OpenJPA 1.2 on glassfish. We use entity caching to improve our
> application performance.
> As you may know, there are two options to set cache settings in an
> OpenJPA-based application: At persistence-level that use persistence.xml,
> we
> just set DataCache there to enable entity caching in the whole application:
> <property name="openjpa.DataCache" value="true"/>
>
> and at entity-level that requires @DataCache annotation:
>
> @DataCache(enabled=true)
> public class OpenJPACacheTest { ... }
>
> The first question is which method has the highest priority? Using xml or
> annotation? Is annotation overrides cache settings in persistence.xml? For
> e.g. if I enable cache on persistence.xml and disable it on entity level
> using enabled=false, which setting is applied finally?
>
> And the second question is about setting entity cache timeout in
> persistence.xml. I found out setting cache time-out to evict an entity
> using
> DataCache annotation is doable after a special time out expiration. We can
> use timeout attribute from @DataCache annotation:
>
> @DataCache(timeout=10000)
> public class OpenJPACacheTest { ... }
>
> But for now, can I set entity cache timeout on persistence.xml? And if the
> answer is yes, which method has the highest priority again?
>
> Thanks for any tips,
> Nasseria
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Setting-entity-cach-on-persistence-xml-or-DataCache-annotation-tp5654852p5654852.html
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>