title: Hibernate 2nd level data cache and integration/acceptance testing
body: <p>I have an JPA/Hibernate/Spring/Tomcat web application with second level data cache enabled for performance reasons. And the cache does its work very well!</p>
  
  <p>I also have a Cucumber test suite which adds some test data directly to the application's database and then performs some Selenium steps. Of course it fails as the application doesn't see the updates because of the 2nd level cache.</p>
  
  <p>I know I can make special build for testing with cache disabled (by passing some boolean property for Maven filtering or similar) But there are a lot of @Cache annotated entities so disabling the cache makes the application fail with exception "Second level cache is not enabled".</p>
  
  <p>Another approach could be to use ehcache remoting to clear the cache or configure it with zero object lifetime or similar.</p>
  
  <p>I can also create my test data using application UI only but this adds unnecessary complexity to the test cases so I prefer to write them to the DB before test run.</p>
  
  <p><strong>Could anybody share their approach to integration-test applications with 2nd level data cache enabled?</strong></p>