You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Fay Wang <fy...@yahoo.com> on 2008/05/02 22:37:00 UTC

DataCache and refresh problem

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

Re: DataCache and refresh problem

Posted by Fay Wang <fy...@yahoo.com>.
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 <fy...@yahoo.com> wrote:

> From: Fay Wang <fy...@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