title: SpringFramework: @Transactional(readOnly = true) not working with h2
body: <p>I am doing transaction testing with the SpringFramework.
  I have the following classes.</p>
  
  <p><strong>UserService.class</strong></p>
  
  <pre><code>@Transactional
  public interface UserService {
      void add(User user);
  
      @Transactional(readOnly = true)
      User get(String id);
  
      @Transactional(readOnly = true)
      List&lt;User&gt; getAll();
  
      void deleteAll();
  
      void update(User user);
  }
  </code></pre>
  
  <p><strong>UserServiceImpl.class</strong></p>
  
  <pre><code>public class UserServiceImpl implements UserService {
      // skip some methods
      @Override public void update(User user) { userDao.update(user); }
  }
  </code></pre>
  
  <p><strong>TestUserService.class</strong></p>
  
  <pre><code>public class TestUserService extends UserServiceImpl {
      @Override
      public List&lt;User&gt; getAll() {
          for (User user : super.getAll()) {
              // try to update in get* method. it's read-only. 
              super.update(user);
          }
          return null;
      }
  }
  </code></pre>
  
  <p><strong>Test Code</strong></p>
  
  <pre><code>@Test(expected = TransientDataAccessResourceException.class)
  public void readOnlyTransactionAttribute() {
      testUserService.getAll();
  }
  </code></pre>
  
  <p>This test code is a success case when using mysql. But it fails when using H2 In-memory database. This is because the transaction completes without an exception.</p>
  
  <p>I read the Spring Framework documentation and found the following:
  <a href="http://docs.spring.io/spring/docs/4.3.x/javadoc-api/org/springframework/transaction/annotation/Transactional.html#readOnly--" rel="noreferrer">http://docs.spring.io/spring/docs/4.3.x/javadoc-api/org/springframework/transaction/annotation/Transactional.html#readOnly--</a></p>
  
  <blockquote>
    <p>This just serves as a hint for the actual transaction subsystem; it will not necessarily cause failure of write access attempts. A transaction manager which cannot interpret the read-only hint will not throw an exception when asked for a read-only transaction but rather silently ignore the hint.</p>
  </blockquote>
  
  <p>But I wonder if there is a way to pass this test with the H2 database.</p>