You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Daniel Lee (JIRA)" <ji...@apache.org> on 2007/06/25 00:46:25 UTC

[jira] Created: (OPENJPA-265) datacache does not get committed when application commit after a query

datacache does not get committed when application commit after a query
----------------------------------------------------------------------

                 Key: OPENJPA-265
                 URL: https://issues.apache.org/jira/browse/OPENJPA-265
             Project: OpenJPA
          Issue Type: Bug
          Components: datacache
    Affects Versions: 1.0.0
            Reporter: Daniel Lee


I'm that sure whether this is a bug or not but what is observed is that the application commit in the following code does not trigger commit on the datacache.
=============================================================
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("demo");
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    Customer c = (Customer) em.createQuery("select c from Customer c where c.name='Harry Auto'").getSingleResult();
    em.getTransaction().commit();
=============================================================

Is this normal because there is no update?  It make sense that there is no need to flush on the database, but the datacache has been newly loaded with the customer "Harry Auto" and the objects that are eagerly related to "Harry Auto".  If datacache is not committed, another transaction does not see the loaded data in the data cache and will redundantly query the database again.  Is this a bug or working as design?  Many thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (OPENJPA-265) datacache does not get committed when application commit after a query

Posted by "Patrick Linskey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-265?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Patrick Linskey resolved OPENJPA-265.
-------------------------------------

    Resolution: Invalid

OpenJPA's data cache implementation as currently implemented is updated outside the bounds of the transaction. As such, it is not an XA resource, and does not participate in the transaction per se. It receives notifications of committed data during an afterCompletion() callback.

Since the cache never receives updates until after a transaction has successfully completed, there is no opportunity for the cache to be populated with invalid data. However, since the cache update is not part of the commit itself, it is possible for a cache to have stale data, if somehow an exception is raised between the commit to the database and the cache update logic. Since the OpenJPA cache is designed primarily for the optimistic transaction model, and the cache already handles self-healing in the face of optimistic transaction failures and stale data, this increased staleness opportunity is unfortunate but not fatal.

It would be possible to change the current implementation (or create a new implementation) that is transactional. However, there is a significant additional cost to doing this, as all transactions would then need to be XA transactions. Further, OpenJPA would be taking up two XA slots, meaning that the two-resource XA optimization would not be available if any other data sources were added to the XA tx.

DataCache.commit() would be better-named DataCache.notifyOfCommit().

> datacache does not get committed when application commit after a query
> ----------------------------------------------------------------------
>
>                 Key: OPENJPA-265
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-265
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: datacache
>    Affects Versions: 1.0.0
>            Reporter: Daniel Lee
>
> I'm that sure whether this is a bug or not but what is observed is that the application commit in the following code does not trigger commit on the datacache.
> =============================================================
>     EntityManagerFactory emf = Persistence.createEntityManagerFactory("demo");
>     EntityManager em = emf.createEntityManager();
>     em.getTransaction().begin();
>     Customer c = (Customer) em.createQuery("select c from Customer c where c.name='Harry Auto'").getSingleResult();
>     em.getTransaction().commit();
> =============================================================
> Is this normal because there is no update?  It make sense that there is no need to flush on the database, but the datacache has been newly loaded with the customer "Harry Auto" and the objects that are eagerly related to "Harry Auto".  If datacache is not committed, another transaction does not see the loaded data in the data cache and will redundantly query the database again.  Is this a bug or working as design?  Many thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-265) datacache does not get committed when application commit after a query

Posted by "Patrick Linskey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-265?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12507808 ] 

Patrick Linskey commented on OPENJPA-265:
-----------------------------------------

> If datacache is not committed, another transaction does not see
> the loaded data in the data cache and will redundantly query the database again.

To follow up: since DataCache.commit() is poorly named, and the data cache is non-transactional, the data loaded during one transaction will be available to other transactions immediately. So, the data cache is somewhere between a READ_COMMITTED and REPEATABLE_READ, semantically. The only exception is if direct JDBC work is performed on the data source before OpenJPA reads data from the database; in these situations, cache population may be turned off by calling OpenJPAEntityManager.setPopulateDataCache(false).

> datacache does not get committed when application commit after a query
> ----------------------------------------------------------------------
>
>                 Key: OPENJPA-265
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-265
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: datacache
>    Affects Versions: 1.0.0
>            Reporter: Daniel Lee
>
> I'm that sure whether this is a bug or not but what is observed is that the application commit in the following code does not trigger commit on the datacache.
> =============================================================
>     EntityManagerFactory emf = Persistence.createEntityManagerFactory("demo");
>     EntityManager em = emf.createEntityManager();
>     em.getTransaction().begin();
>     Customer c = (Customer) em.createQuery("select c from Customer c where c.name='Harry Auto'").getSingleResult();
>     em.getTransaction().commit();
> =============================================================
> Is this normal because there is no update?  It make sense that there is no need to flush on the database, but the datacache has been newly loaded with the customer "Harry Auto" and the objects that are eagerly related to "Harry Auto".  If datacache is not committed, another transaction does not see the loaded data in the data cache and will redundantly query the database again.  Is this a bug or working as design?  Many thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.