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