Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 4738 invoked from network); 2 May 2008 20:37:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 May 2008 20:37:31 -0000 Received: (qmail 21136 invoked by uid 500); 2 May 2008 20:37:32 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 21107 invoked by uid 500); 2 May 2008 20:37:32 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 21094 invoked by uid 99); 2 May 2008 20:37:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 May 2008 13:37:32 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [216.252.110.51] (HELO web55805.mail.re3.yahoo.com) (216.252.110.51) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 02 May 2008 20:36:47 +0000 Received: (qmail 39666 invoked by uid 60001); 2 May 2008 20:37:00 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type:Message-ID; b=hBj5oc1s/UQhvF8L1BM0f6FHzPj03kJcXQwurFOzC93oSWHXvj31yiTcY/dbBVuDSxh83xVUqniptiwZCl2KcQc3QGcum5InPA9LGv4ooFN75vO92NZr0eBPJ07xz4QDwLWWjPVPL5++EPlMVHUbCZ1Qu++Y7TyuLsmEfzNxQtQ=; X-YMail-OSG: 63YSwp0VM1kLKqNZy8LefcEzMslIP5bf4_gOQQezgdGGZkXLLglqZkv4ZEDLBZ0gSg-- Received: from [129.42.184.35] by web55805.mail.re3.yahoo.com via HTTP; Fri, 02 May 2008 13:37:00 PDT X-Mailer: YahooMailWebService/0.7.185 Date: Fri, 2 May 2008 13:37:00 -0700 (PDT) From: Fay Wang Reply-To: fyw300@yahoo.com Subject: DataCache and refresh problem To: dev@openjpa.apache.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Message-ID: <139291.39027.qm@web55805.mail.re3.yahoo.com> X-Virus-Checked: Checked by ClamAV on apache.org 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" 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