To run Spring Data JPA with an embedded database, add Spring Boot’s JPA starter and an embedded database engine such as H2 or HSQLDB. With one supported engine on the classpath, Spring Boot can configure the data source without a database URL. The key decisions are which engine to include, how Hibernate manages the schema, and whether the database is suitable for temporary development or test data—not durable storage.
What Spring Boot configures—and what you must add
spring-boot-starter-data-jpa brings in Hibernate, Spring Data JPA, and Spring ORM. You also need an embedded database engine dependency. Spring JDBC, which Spring Boot uses for embedded database auto-configuration, is included transitively by the JPA starter.
For Maven, the Spring Boot SQL reference shows this pairing with HSQLDB:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>
The same pattern works with H2 by adding its engine dependency at runtime. Check the dependency version against the Spring Boot version used by your project; the starter is designed to manage compatible library versions.
Recommended Free Tools
#1 Best Overall
Spring Boot’s current SQL reference lists H2 and HSQL as supported embedded databases. Derby is also mentioned there, but marked deprecated. If multiple embedded engines are on the classpath, choose one with spring.datasource.embedded-database-connection. Set it to none to disable embedded database auto-configuration. With a single embedded engine, Boot can create a data source without an explicit connection URL. Spring Boot SQL databases reference.
Place entities and repositories where Boot can find them
By default, Spring Boot scans its auto-configuration packages for classes annotated with @Entity, @Embeddable, or @MappedSuperclass, and looks there for Spring Data repositories. Keep those classes in the application package or a subpackage so they fall within the default scan tree; otherwise, configure scanning explicitly.
Rank #2
A repository can derive queries from method names—for example, findAllByState(String state). For a query that needs an explicit definition, use Spring Data JPA’s @Query. This lets you start with a small repository interface without writing database connection or query boilerplate.
Choose the database lifetime deliberately
An in-memory embedded database is temporary. Its contents do not survive application shutdown, so it is useful for isolated development runs and tests, but not for application data that must remain available. Spring Boot’s documentation puts it plainly: “Obviously, in-memory databases do not provide persistent storage.” If you provide an H2 JDBC URL yourself, the reference also cautions about shutdown behavior and documents DB_CLOSE_ON_EXIT=FALSE for H2. Follow the guidance for the Boot version and URL configuration you actually use rather than assuming every embedded setup has the same lifecycle.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Rank #3
Set the schema lifecycle instead of relying on defaults
Hibernate’s schema behavior is controlled by spring.jpa.hibernate.ddl-auto. The documented options are:
none: do not manage the schema through Hibernate.validate: check that the schema matches the mapped entities.update: update the schema to reflect the mappings.create: create the schema when the application starts.create-drop: create the schema at startup and drop it when the application ends.
Spring Boot documents create-drop as the default when using an embedded database without a schema manager such as Flyway or Liquibase; otherwise, its default is none. Defaults can therefore change the outcome when the database or project setup changes. Set the property explicitly when schema lifecycle matters, and decide whether Hibernate, a migration tool, or another mechanism owns schema changes. Spring Boot database initialization guide.
Rank #4
Spring Boot also supports schema.sql and data.sql. Coordinate those scripts with Hibernate’s DDL setting rather than assuming initialization order or behavior will be identical across database platforms. When switching platforms, review both schema generation and initialization: embedded tables and seeded data do not automatically appear in the new database. To select platform-specific scripts, use spring.sql.init.platform; Boot can then look for schema-${platform}.sql and data-${platform}.sql.
Test repositories with the right Spring test scope
Use @DataJpaTest for persistence-focused tests
@DataJpaTest configures JPA entities and repositories and uses an embedded database when one is available. Tests are transactional and roll back by default, which helps keep persistence tests isolated. This slice test does not load ordinary application components or configuration properties by default, so it is best when the behavior under test is limited to the persistence layer.
Use a full application test when the wider context matters
If a test needs the full Spring Boot application configuration as well as an embedded database, use @SpringBootTest with @AutoConfigureTestDatabase. This exercises a broader context than the JPA slice, so choose it when the additional application setup is part of what the test needs to verify. See the Spring Boot testing reference and the @DataJpaTest API documentation.
Keep the H2 console out of production
For development, Spring Boot can enable the H2 web console with spring.h2.console.enabled. The console is a development aid, not a production administration interface. The Boot reference warns against enabling it in production. If Spring Security is present, account for the console’s frame and CSRF requirements in the security configuration rather than weakening protections broadly. See the Spring Boot SQL databases reference for the console configuration details.
Check these details when moving beyond the embedded setup
- Database selection: Remove unintended embedded engine dependencies or explicitly select one when more than one is present.
- Durability: Move data that must persist to a database configured for durable storage; an in-memory database is not a substitute.
- Schema ownership: Choose Hibernate DDL, a migration tool, or SQL initialization as the schema-management approach, and configure it deliberately.
- Platform-specific SQL: Review initialization scripts for the destination database and use
spring.sql.init.platformif separate script sets are needed. - Test scope: Use
@DataJpaTestfor repository and mapping behavior, and a full application test when behavior outside the persistence layer matters.
Spring Boot’s rolling references describe current behavior, but their version context matters: the testing reference is on the Spring Boot 4.2 documentation path, the @DataJpaTest API page identifies 4.1.1, and the Spring Framework embedded-database page identifies 7.0.9. Confirm property support and defaults against the documentation for the Boot version selected for your project.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

