Free your mind with JDBI

using explicit SQL mappers...

...in enterprise applications

Maciej Małecki, Architecture Community, Capgemini 2021.

db

db

Why?

Hibernate Logo
1: SQL-POJO binding
2: SQL dialect-agnostic
3: transparent persistence

Transparent persistence

change detection
associations
n+1
proxies
no boundaries
Hibernate Logo
fetching strategies
entity graphs
stateful session

⇯⇯⇯ hidden complexity ⇯⇯⇯

What are the SQL mappers?

1: SQL-POJO binding
JOOQ JDBI spring
r2dbc JDBC

When should I consider a mapper?

JOOQ JDBI spring
  • 🧅, hexagonal, DDD
  • "read-only" app - dump data on screen
  • "write-only" app - data importers & updaters
  • CQRS
  • event sourcing
  • "small" apps of any kind
SQL ↭ POJO mapper
fluent API
... or declarative API
wraps around JDBC
JDBI
native SQL
no limitations
no fake persistence
get what you code
(and nothing more)

JDBI

example config in Spring

... and the same in Spring/Kotlin

Simple SELECT

... and in Kotlin

Simple INSERT

or simply

or bean mapped INSERT

Result beans

if names are excluded from the bytecode

... or use Kotlin

SQL Object

SQL Objects / Transactions

Templating

Find by criteria (Devonfw style)

"advanced" topics

Entity & event sourcing

Item stock

DAO implementation for event sourcing

Optimistic locking

Classy CRUDs

Q?