Domain-Driven Design with Relational Databases Using Spring Data JDBC

SpringDeveloper · 63K views · 2019 · 1:10:30

Open on YouTube

Software architecture & designDatabases & storageSoftware practice, open source & careerstalk

Why Stack Overflow recommends it

Stack Overflow users link it when explaining how Spring Data JDBC models DDD aggregates, such as why only the aggregate root carries an @Id and how it differs from JPA.

Recommended by 2 people across 2 different months, 2020 to 2025.

What it is

A SpringOne Platform 2019 conference talk by Jens Schauder of Pivotal on applying domain-driven design to relational databases. It explains Aggregates, AggregateRoots and Repositories, why taking them seriously makes much of JPA's complexity unnecessary, and how to build a persistence layer with Spring Data JDBC.

What people said

Recommends Datum Geek · 2020-02 · Stack Overflow · on “Spring Data JDBC - Clob column to String property in POJO not working”

There's a very nice example here that solves the problem: [LINK] The solution amounts to adding a configuration that registers a converter that can extract the CLOB data to the String property import java.sql.Clob; import java.sql.SQLException; import java.util.Arrays; import org.springframework.context.annotation.Configuration; import org.springframework.core.convert.converter.Converter; import org.springframework.data.jdbc.core.convert.JdbcCustomConversions; import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration; import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories; import org.springframework.data.relational.core.mapping.Embedded.Nullable;

Recommends Bidone · 2025-08 · Stack Overflow · on “Spring Data JDBC - mapping a series of nested one-to-many relationships inside an aggregate”

This is a request for clarification after watching a video about Spring Data JDBC. I have an aggregate made of Book (aggregate root), BookCopy and BookCopyQualityControl. A Book has many BookCopy, and a BookCopy has many BookCopyQualityControl. I want only the Book class to have an @Id (Long), because it is the aggregate root (this is suggested here [this video] ). In my database: BOOK's primary key is ID; BOOK_COPY's primary key is the couple (BOOK_ID, COPY_NUMBER), with BOOK_ID referencing BOOK(ID); BOOK_COPY_QUALITY_CONTROL's primary key is the triple (BOOK_ID, COPY_NUMBER, QUALITY_CONTROL_NUMBER), with (BOOK_ID, COPY_NUMBER) referencing BOOK_COPY(BOOK_ID, COPY_NUMBER). I am trying to implemen

Cites Murilo Carlos Cardoso · 2020-05 · Stack Overflow · on “DDD, JPA and non-default constructors”

In your specific situation you can make the non-argument constructor private. But soon another JPA requirement will force you to make another workaround; voiceofunreason gave you the right answer. The right way is to have an adapter in the infrastructure/persistence layer that receives your domain object and then convert it to a JPA anemic model and vice versa. Some other options that fits better without too much conversions: 1 - Spring Data JDBC is trying to absorb Aggregates concept [this video] ; [LINK] 2 - Persist your aggregate as a json in a relational database. Vaughn Vernon proposed an implementation -> [LINK] 3 - Document oriented database such as [LINK] among others...

Cites Jens Schauder · 2023-01 · Stack Overflow · on “Spring initialzr - At SQL category, what do I choose between JDBC API, Spring Data JPA and Spring Data JDBC”

JDBC itself is the low level API to interact with SQL databases. It is a pain to use, since you have to create each and every SQL statement on your own using String values, handle all the checked exceptions in often non-trivial ways and map results to your domain classes. All this is tedious and error prone, so you almost certainly want something on top of it. JDBC API in Spring Initializr is a bunch of classes that are part of Spring Framework, that help with the repetitiveness and error proneness of the tasks mentioned above but doesn very little beyond that. If you use JDBC API you will mainly work with JdbcTemplate or NamedParameterJdbcTemplate . Most of error handling will be done for y