Hi,
I am working with JPA (1.0 or 2.) + hibernate (3.4.0 or 3.6.0) and I have run into a problem with I think caching somewhere. What I do:
- Find an object with my JPA class (row in the database with a particular id)
- update a boolean flag on the object (tinyint field in the database)
- persist the object
- grab the entire table from the database with getResultList() hoping to have the change reflected.
Problem:
The change is reflected with getResultList the first time I call it, but the second time it show the previous state. The third time it shows correctly; the fourth, the previous state; etc. It seems to alternate between the two state each time I call getResultList on the table.
Some code for #3 above:
EntityTransaction entityTransaction = entityManager.getTransaction();
entityTransaction.begin();
entityManager.persist(object);
entityTransaction.commit();
entityManager.refresh(object);
Code for #4:
Query query = entityManager.createQuery("from " + object.getName());
List<T> resultList = query.getResultList();
In my efforts to solve the problem, I have:
1.Turned L2 and query cache off in the persistence.xml with:
<property name="hibernate.cache.use_query_cache" value="false"/>
<property name="hibernate.cache.use_second_level_cache" value="false"/>
2.forced a cache eviction before running getResultList() with (using JPA 2.0):
entityManager.getEntityManagerFactory().getCache().evictAll()
3.tried calling refresh() all over the place - to no effect.
Am I missing something?
Any help would be appreciated.
Thanks, sop