[ 
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.

Reply via email to