Search code examples
spring-data-jdbc

Is it plausible to uswe spring-data-jdbc in a scenario where the DB-schema differs from the domain-model


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?


Solution

  • 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.