openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <>
Subject Re: Setting entity cach on persistence.xml or @DataCache annotation?
Date Wed, 20 Oct 2010 15:45:00 GMT

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 :

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,

On Wed, Oct 20, 2010 at 8:32 AM, nasseria1 <> 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:
> Sent from the OpenJPA Developers mailing list archive at

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message