Search code examples
springspring-jdbcr2dbcspring-data-jdbc

R2DBC vs Spring Jdbc Vs Spring Data JDBC?


On Using Spring JDBC which works very well and has some improvements over JPA when using Batch processing.

I would love to learn why to use Spring Data JDBC when you already have Spring JDBC.

I would love to learn why to use R2DBC when you already have Spring JDBC.


Solution

  • When you would use R2DBC is easy, it’s when you are building an application that is non-blocking. Everything in the stack has to be non-blocking, including the database driver. JDBC is inherently blocking, people try schemes to get around it but it is not great. If you aren’t building a non-blocking application you wouldn’t use R2DBC.

    For the part about when to use spring data JDBC, it looks like it gives you a simpler way to create repositories and map data, as long as you’re ok with their opinionated framework, you are ok with not having all the complex mappings you get with JPA, and you want the DDD concepts (like aggregate root). Otherwise Spring JDBC requires more code to create your data access objects but may give more control. https://docs.spring.io/spring-data/jdbc/docs/2.2.4/reference/html/#reference describes more about why to use Spring Data JDBC. It is simplicity vs control.