Currently, the trending architecture involves applications being stateless and storing states in databases. It is very important what type of application you choose - blocking or non-blocking. Since each of them requires its own description and in-depth analysis, in this article, we will consider only the options for blocking the most popular applications.

Constraints and Requirements.

As the candidate for integration, we will consider a reactive application written in Kotlin, with Spring Boot as the primary framework. We need to determine the database integration approach.

So there are criteria. Our approach should:

Compatibility with Spring is essential, encompassing aspects like configuration, health monitoring, metrics tracking, and transaction management. Non-blocking capabilities are imperative, given our utilization of WebFlux and Reactor. It should facilitate straightforward query execution with a minimalistic implementation, reducing the need for excessive boilerplate code.

The solution should offer flexibility for intricate queries, allowing for customization through custom queries or even dynamic SQL statements. Ideally, it should support both the Repository pattern and the Active Record pattern. Ideally, it should provide a streamlined method for constructing complex objects in a single database request.

Here are some of the most popular and trending solutions you might want to consider using:

Let's take a look at each of them.

Spring Data JPA.

It is a framework within the Spring ecosystem that simplifies database access in Java applications using the Java Persistence API (JPA). It provides a higher-level, repository-centric approach to interact with relational databases, enabling developers to write data access code more easily and efficiently. Spring Data JPA abstracts many common data access tasks, reducing the need for boilerplate code and provides a consistent and standardized way to work with databases across various JPA implementations. It also supports features like query creation from method names and custom query definitions, making it a valuable tool for developing data-centric applications in a Spring environment.

It's particularly well-suited for building classic RESTful applications with clearly defined models and CRUD endpoints.

Here's a breakdown of its strengths and weaknesses:

Strengths of Spring Data JPA:

Weaknesses of Spring Data JPA:

This revised version provides a clearer and more structured presentation of the strengths and weaknesses of the Spring ORM realization.

However, we will undoubtedly find ourselves asking whether we want to use the ORM pattern. The initial response might be, 'Yes, absolutely!' However, delving deeper into this question reveals that there is more to analyze.

So, what is ORM?

Object-Relational Mapping (ORM) is a programming technique and framework used in software development to bridge the gap between object-oriented programming languages and relational databases. It provides an abstraction layer that allows developers to interact with a database using object-oriented code and concepts rather than writing raw SQL queries.

If you are ready to use it, be sure to use Spring Data JPA.

Spring JDBC

For those who have to write complex SQL queries and want more controls on their DAO level.

Spring JDBC provides a simplified and efficient approach to working with relational databases in Java applications. It offers a set of APIs and abstractions that streamline database access, making it easier for developers to manage database connections, execute SQL queries, and handle results.

There are Spring JDBC pros:

There are Spring JDBC cons:

jOOQ

jOOQ - is a Java-based database access library and code generation tool that simplifies database interaction for Java applications. It stands for "Java Object Oriented Querying" and provides a domain-specific language (DSL) for querying relational databases. jOOQ focuses on offering a strongly typed, SQL-centric approach to database access, which enables developers to write database queries in a more structured and type-safe manner.

Advantages of jOOQ:

Disadvantages of using jOOQ:

As you can see, jOOQ has quite significant negative aspects. Considering that it requires additional configuration to work with the spring boot application, this lowers it to last place in the list of proposed options. But you should definitely keep it in mind if, for some reason, you are limited in the use of Spring Data JPA or Spring JDBC.

Photo by Tobias Fischer on Unsplash