# The best way to clean up test data with Spring and Hibernate

DevFeed: [The best way to clean up test data with Spring and Hibernate](<https://devfeed.tech/articles/the-best-way-to-clean-up-test-data-with-spring-and-hibernate-21982.md>)

Original publisher: [Read original article](<https://vladmihalcea.com/clean-up-test-data-spring/>)

Author: vladmihalcea

Published: 2025-11-11T08:05:24Z

Content type: tutorial

Language: en

Sources: [Vlad Mihalcea](<https://devfeed.tech/sources/vlad-mihalcea.md>)

Topics: [Spring Boot](<https://devfeed.tech/topics/spring-boot.md>), [Integration testing](<https://devfeed.tech/topics/integration-testing.md>), [Testing](<https://devfeed.tech/topics/testing.md>), [Java](<https://devfeed.tech/topics/java.md>), [Spring Framework](<https://devfeed.tech/topics/spring-framework.md>)

Tags: [cleanup](<https://devfeed.tech/tags/cleanup.md>), [hibernate](<https://devfeed.tech/tags/hibernate.md>), [integration-testing](<https://devfeed.tech/tags/integration-testing.md>), [java](<https://devfeed.tech/tags/java.md>), [jpa](<https://devfeed.tech/tags/jpa.md>), [schema](<https://devfeed.tech/tags/schema.md>), [spring](<https://devfeed.tech/tags/spring.md>), [spring-boot](<https://devfeed.tech/tags/spring-boot.md>), [test-data](<https://devfeed.tech/tags/test-data.md>), [testing](<https://devfeed.tech/tags/testing.md>), [truncatemappedobjects](<https://devfeed.tech/tags/truncatemappedobjects.md>)

## AI overview

This tutorial examines how to clean up test data in Spring and Hibernate integration tests. It argues that relying on @DataJpaTest for automatic transaction rollback is not always appropriate and discusses limitations of its SQL logging, including its inability to show bind parameter values or indicate whether batching is used.

## Source excerpt

Introduction In this article, I'm going to show you the best way to clean up test data when using Spring and Hibernate. While it's very common to use the @DataJpaTest annotation when implementing integration tests, in this blog post, you will see why you are better off avoiding using this annotation. Why I don't use @DataJpaTest As explained by the manual, Spring Boot provides the @DataJpaTest annotation for Spring Data JPA integration testing. Once the @DataJpaTest annotation is added to an integration test, Spring Boot will make the following changes to the... Read More The post The best way to clean up test data with Spring and Hibernate appeared first on Vlad Mihalcea.