简体   繁体   中英

How to use Spring Data JDBC without annotations?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM