persistence@glassfish.java.net

Re: Configuration of Client vs. Shared Cache

From: Adam Bien <abien_at_adam-bien.com>
Date: Mon, 19 Nov 2007 17:45:47 +0100

Hi Gordon,

thank you very much for the fast reply. I'm thinking of the Persistence
Context as an Identity HashMap, which primary goal is to keep the
consistency of the entities in a transaction.
However in our application (it is a rich client, which connects directly
to the database without an application server or middleware), it seems
like once loaded objects are hold
by the EntityManager until the method clear is invoked or the Entity
Manager is closed (we are using the current build - TopLink v2b58). The
Entity Manager remains open between the transactions - it is even not
cleared. We would like to work with the entities, without loading them
from the database every time.

We are using data binding between the domain objects and the UI - so
clearing the entity manager makes the entities detached (and makes the
GC run) - the whole app has to be refreshed then. This in turn is not
wished by the end users :-).

I'm wondering, whether it would be possible to hold the objects using
weak-reference in the L1 cache / transactional cache. Then all unneeded
objects would be automatically garbage collected. The object-identity
would be still provided with this setting... Now the memory consumption
increases - until Out Of Memory occurs...

any thoughts?

thank you in advance,


regards,

adam



Gordon Yorke schrieb:
> Hello Adam,
> You may be confusing the Persistence Context with a cache?
> Sometimes the UnitOfWork which is the implementation of the
> Persistence Context in TopLink is described as a cache to explain some
> of its behaviours but its behaviour is beyond that of a cache.
> Because the Unit0fWork must track all objects that were ever read
> through or registered by the UnitOfWork to full its behavioural
> requirements the TopLink cache settings do not apply.
> --Gordon
>
>
> Adam Bien wrote:
>> Hi All,
>>
>> TopLink cache consists of two parts:
>> 1. Client/L1
>> 2. Shared/L2
>>
>> Is it possible to configure them independently? In the TopLink
>> reference there are two sections:
>>
>> http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-extensions.html#BABGDJBC
>>
>>
>> It seems like the @Cache annotation addresses the Client/L1 cache.
>> The properties (
>>
>> eg. <property name="toplink.cache.type.Order" value="Full"/>) the L2.
>>
>> Is it possible to configure both caches using the persistence.xml
>> properties?
>>
>> I would like to configure Weak Caches for both levels, however it
>> seems like the L1 cache is still "Full" (or it uses "hard" references
>> to entities)
>>
>> thank you in advance!,
>>
>> adam bien
>>
>


-- 
 Consultant, Author, Java Champion
 
 Homepage: www.adam-bien.com
 Weblog: blog.adam-bien.com
 eMail:  abien_at_adam-bien.com
 Mobile: 0049(0)170 280 3144
 Books: Enterprise Architekturen (ISBN: 393504299X),
        Java EE 5 Architekturen  (ISBN: 3939084247),
        J2EE Patterns, J2EE Hotspots, Enterprise Frameworks and Struts