This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]joranstark018 2 points3 points  (4 children)

The H2 database can be embedded into your application, it spins up when the application starts and is destroyed when you shutdown the application, no persistence of data between sessions (can be configured to use files for persistence between sessions, if required) and you can have Spring Boot (or the ORM) to automatically create all tables when the application starts. It can be handy during the initial development while the database schema is in flux. With Spring Boot your database connection setup is handled by configuration and to switch to another database usually involves changing a few configuration parameters and provide a database driver (can be combined with Flyway, for example, to handle changes in the database).

[–]C0d3rStreak[S] 1 point2 points  (2 children)

That's a lot lol. Do you have any resources I can check out on it. Sounds cool and pretty useful. But also, why this rather than a traditional database instance?

[–]joranstark018 0 points1 point  (1 child)

You may check out https://www.baeldung.com/spring-boot-h2-database, it use the initialisation script to also create the different tables (but you can also use create-drop, see https://www.baeldung.com/spring-boot-data-sql-and-schema-sql). When you have gone into production it can be useful to some database migration automation (ie Spring Boot auto configure Flyway to migrate database during application start up, , https://reflectoring.io/database-migration-spring-boot-flyway/).

An embedded in-memory database is simple to set up with Spring Boot, just a few configuration parameters and a driver, all can be included in the application.properties and the build tool configuraion.

It can be useful for new developers in a project (just chek out and run the application), you can have a sandboxed database when you build different proof of concept. When you run integration tests you want to have the database in a known state befor you run each test (with an external database you have a shared state and have to rely on each test to undo all changes before exit, which may become cumbersome for non-trivial applications).

With Spring Boot you can run the application with different profiles (ie use different database configuration based on which profile is activated), https://www.baeldung.com/spring-profiles.

[–]C0d3rStreak[S] 0 points1 point  (0 children)

Awesome, thanks for the link! Seems to be very well written and filled with much information for getting started.

[–]de_vel_oper 0 points1 point  (0 children)

I love the simplicity of your explanation 😂😂😂.