2

I'm working on a new project, using concepts like clean architecture, protecting my model and business rules from external dependencies and frameworks. Also, I prefer not to use traditional ORM libraries (like JPA/Hibernate) and have choose to use plain jdbc (through spring jdbctemplate).

It was going pretty well, but I'm getting tired of write 20x almost the same query for all my domain classes on a basic crud reposity. So, I take a look at Spring Data JDBC, but it appears that it's necessary to add annotations on my domain classes to make it work properly. I really don't want to do that, first because I want to make my domain cleaner as possible from any dependencies, and second because this is one of the (many) things I really dislike on JPA.

I was wondering that, the repository needs only 2 things: a rowmapper definition and the PK definition (and both could be defined at the repository itself) avoiding the complete use of annotations.

So, my question is there any way to use Spring Data JDBC without annotations?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
DanielSP
  • 349
  • 3
  • 13
  • Also, the thing I dislike the most on JPA/Hibernate is the usage of DTOs and conversion services, so it is not an option here. – DanielSP Jun 08 '20 at 17:28

1 Answers1

1

No, there is no easy way to use Spring Data JDBC (https://spring.io/projects/spring-data-jdbc).

What you could do is to replace those classes that do the annotation interpretation (RelationalPersistentEntityImpl, and BasicRelationalPersistentProperty) and replace them with something that gets the information from elsewhere.

There is a different framework wich might fit the bill which is also named Spring Data JDBC ‍♀️ https://github.com/nurkiewicz/spring-data-jdbc-repository

It seems pretty close to what you are looking for but it has its last commit 6 years ago and is archived on Github.

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