DEV Community

loizenai
loizenai

Posted on

Kotlin – Integrate H2 database with Spring JPA( by Spring Boot) in Embedded mode

https://grokonez.com/spring-framework/spring-boot/kotlin-spring-boot/kotlin-integrate-h2-database-spring-jpa-spring-boot-embedded-mode

Kotlin – Integrate H2 database with Spring JPA( by Spring Boot) in Embedded mode

H2 database is a pure Java, open source and very fast engine. We can use H2 for development, testing and performance benchmarking. So in the tutorial, JavaSampleApproach will show how to integrate H2 database with Kotlin SpringBoot and Spring JPA in Embedded mode.

I. H2 database and SpringBoot integration

H2 database has small footprint (smaller than 1.5 MB) with low memory requirements. It supports for multiple schemas and standard SQL, JDBC API. We can use H2 with disk based or in-memory databases.

H2 can be built by following mode:
– Embedded mode (local connections)
– Server mode (remote connections)
– Mixed mode (local and remote connections)

In the tutorial, We focus on Embedded mode to integrate H2 database and SpringBoot Application.

kotlin h2 springboot jpa - architecture - H2-Embedded

How to configure it with SpringBoot?
-> Spring Boot has a built in H2 database, so We just add below dependency:

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
</dependency>

H2 supports a convenient web based data console to interact with database while the development:

kotlin h2 springboot jpa - architecture - H2-Database-console

II. Practice

In the tutorial, We create a Spring JPA Web application which uses Spring JPA to interact with H2 database in Embedded mode.

Step to do:
– Create Kotlin SpringBoot project
– Configure H2 database
– Implement Kotlin Spring JPA Web Application
– Run & check results

https://grokonez.com/spring-framework/spring-boot/kotlin-spring-boot/kotlin-integrate-h2-database-spring-jpa-spring-boot-embedded-mode

Kotlin – Integrate H2 database with Spring JPA( by Spring Boot) in Embedded mode

Top comments (0)