openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fay Wang <fyw...@yahoo.com>
Subject Re: DataCache and refresh problem
Date Fri, 02 May 2008 22:42:46 GMT
After further investigation, it appears that when DataCache is on (the StoreManager becomes
DataCacheStoreManager), the operations of sm.syncVersion and sm.load are all performed on
the DataCacheStoreManager. 
Just force syncVersion from database is not enough, we also need to force the load from backend,
if this is the expected behavior. Any comment is appreciated.

Fay










--- On Fri, 5/2/08, Fay Wang <fyw300@yahoo.com> wrote:

> From: Fay Wang <fyw300@yahoo.com>
> Subject: DataCache and refresh problem
> To: dev@openjpa.apache.org
> Date: Friday, May 2, 2008, 1:37 PM
> Hi,
>     According to OpenJPA user guide, the refresh action is
> to make sure the 
> persistence state of an instance is synchronized with the
> values in the database. The following test case has the
> expected behavior with the exception when dataCache is
> turned off: 
>     
> EntityManagerImpl em = (EntityManagerImpl)
> emf.createEntityManager();
> EntityA entityA = em.find(EntityA.class, 1);
> em.getTransaction().begin();
> String query1 = "delete from entityA where id=1";
> Query q1 = em.createNativeQuery(query1);
> int count = q1.executeUpdate();
> em.getTransaction().commit();
> em.refresh(entityA); <== EntityNotFound error
> 
> Exception in thread "main"
> <openjpa-0.0.0-rnull nonfatal store error> 
> org.apache.openjpa.persistence.EntityNotFoundException: The
> instance of type "class EntityA" with oid
> "1" no longer exists in the data store.  This may
> mean that you deleted the instance in a separate
> transaction, but this context still has a cached version.
> 
> However, when DataCache is turned on, we no longer see
> EntityNotFound error. This is because in
> BrokerImpl.refreshInternal, before the trip to the database
> to load the fields, the check for version is performed. The
> check for version, unfortunately, is done by
> DataCacheStoreManager (in 
> contrast to JDBCStoreManager when dataCache is off). This
> store manager still keeps the data object in the cache,
> although there is no longer a corresponding row in the
> database. Since the versions of the cached object and the
> object to be refreshed does not change, there will be *no*
> trip to the database to re-load the fields.
> 
> Is this working as design? or is this a bug? Should the
> refresh behave the same regardless of the dataCache
> configuration? If so, the proposed fix will be either 
> (1) openjpa always go to database to reload without
> checking the version when datacache is on.
> (2) openjpa uses JDBCStoreManager to check the version
> during refresh even when dataCache is on (if it is possible
> to switch store manager).
> 
> Any comment?
> 
> Fay
> 
> 
> 
>      
> ____________________________________________________________________________________
> Be a better friend, newshound, and 
> know-it-all with Yahoo! Mobile.  Try it now. 
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

Mime
View raw message