0

I'm considering using spring-data-jdbc for a project. But i don't have any control over the DB-schema. My domain model can be populated by the existing tables, but they differ in many ways.

Examples:

  • A specific aggregate in my model consists of nested Value-Objects. The corresponding table only features flat columns, so the nested Value-Objects would have to be mapped manually.

  • One the other hand, there are aggregates that don't have many nested Value-Objects, but the corresponding tables are organized according to a star-schema, so the values are distributed over many tables (instead of a single one).

I guess this prevents me from using many of the Quality-Of-Life features (like Query-Derivation and Mapping).

Do I actually get anything significant out of spring-data-jdbc in comparison to using a plain JdbcTemplate in this scenario?

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348

1 Answers1

0

The scenario you describe would make me tend towards plain JdbcTemplate. But I would consider using the Aggregate approach Spring Data JDBC does:

  • Load complete aggregates
  • Reference between aggregates using ids, or something like an AggregateReference

And if you have an aggregate that actually can be mapped using Spring Data JDBC you can still do that.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • 1
    Thanks for your answer. I took the middle road now: i created views on the DB that roughly correspond to my aggregates. Furthermore i created DTOs that enable me to use Query-Derivation. Then i only have to map those DTOs to the Aggregates in my model (i do that in encapsulating "Business"-Repositories around the CrudRepositories). They are roughly the same. My Aggregates just tend to be in a more nested structure because i use many ValueObjects instead of "native" types like Integer or String. This way i can use some of the QoL-Feature of spring-data-jdbc without compromising my domain model. – Christian Nockemann Jul 15 '22 at 07:29