For entities with Transactional caching strategy, updated data remains in 2L cache after transaction rollback.
This issue is reproducible on all cache concurrency strategies - not only on TRANSACTIONAL Here's my test case (using Spring and JPA):
@Test public void testHHH5689() throws Exception { final List<Long> holder = new ArrayList<Long>(); transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { Person p = new Person(); p.setName("person1"); em.persist(p); holder.add(p.getId()); em.flush(); em.clear(); em.find(Person.class, holder.get(0)); status.setRollbackOnly(); } }); transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { Person p = em.find(Person.class, holder.get(0)); p.setName("person2"); em.flush(); em.clear(); em.find(Person.class, holder.get(0)); status.setRollbackOnly(); } }); transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { Assert.assertEquals("person1",em.find(Person.class, holder.get(0)).getName()); // FAILS HERE IF CACHE IS ENABLED } }); }
This issue is reproducible on all cache concurrency strategies - not only on TRANSACTIONAL
Here's my test case (using Spring and JPA):