 <p>That’s how I usually annotate my test classes:</p> <pre><code>@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { JPAUnitTestConfiguration.class }) @Transactional //rollback if exception occurs during test method @TransactionConfiguration(defaultRollback = true) //rollback at end of method @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public class FooBarTest { } </code></pre> <p>Add @TransactionConfiguration(defaultRollback = true) to your test class.</p> <p>My transaction configuration:</p> <pre><code>import java.sql.SQLException; import javax.sql.DataSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.FilterType; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.transaction.annotation.EnableTransactionManagement; import ch.ams.pois.repository.AuthTokenRepository; import ch.ams.pois.repository.GroupRepository; import ch.ams.pois.repository.InvitationRepository; import ch.ams.pois.repository.LocationRepository; import ch.ams.pois.repository.UserRepository; @Configuration @EnableTransactionManagement @EnableJpaRepositories(basePackages = JPAConfiguration.JPA_REPOSITORIES_BASE_PACKAGES, includeFilters = @ComponentScan.Filter(value = { UserRepository.class, LocationRepository.class, GroupRepository.class, AuthTokenRepository.class, InvitationRepository.class }, type = FilterType.ASSIGNABLE_TYPE)) public class JPAUnitTestConfiguration extends JPAConfiguration { @Bean public DataSource dataSource() throws SQLException { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); return builder.setType(EmbeddedDatabaseType.H2).build(); } } </code></pre> <p>The dependencies for the persistence layer:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;org.springframework.data&lt;/groupId&gt; &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt; &lt;version&gt;1.3.4.RELEASE&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt; &lt;artifactId&gt;hibernate-jpa-2.0-api&lt;/artifactId&gt; &lt;version&gt;1.0.1.Final&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.hibernate&lt;/groupId&gt; &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt; &lt;version&gt;4.0.1.Final&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;com.h2database&lt;/groupId&gt; &lt;artifactId&gt;h2&lt;/artifactId&gt; &lt;version&gt;1.3.173&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.postgresql&lt;/groupId&gt; &lt;artifactId&gt;postgresql&lt;/artifactId&gt; &lt;version&gt;9.2-1003-jdbc4&lt;/version&gt; &lt;/dependency&gt; </code></pre>