Closed spring-projects-issues closed 6 years ago
Oliver Drotbohm commented
I'd like to veto this for now as it's basically an alternative for a properties file based query declaration mechanism that we already support in other modules. I am not sure Spring Data JDBC already supports that but I'd rather add support for that than introducing yet another query externalization mechanism.
Also, please note that we already have MyBatis support, which is probably the better alternative as it allows more flexible query declarations an mapping definitions
Toshiaki Maki commented
@olivergierke
Thanks for your feedback.
I will also try that approach (maybe in another pull request).
But I think "sql file per query" is more straightforward for JDBC and easier to use than existing META-INF/xxxx-named-queries.properties
since SQL tends to be long and might not be suitable for storing in one file and the file could be also executable.
I agree with MyBatis for dynamic queries for now but using MyBatis only for simple queries could be a bit painful
Oliver Drotbohm commented
While I generally agree with the rationale, we also have to make sure that we do not drown developers in a ton of different ways to achieve the same thing. Spring Data JDBC is a special module as it's pretty focused in it's features and rather recommmends to use other libraries to create and manage SQL statements (jOOQ, MyBatis, Querydsl).
I.e. I'd argue that if you have SQL statements exceeding a certain level of complexity, the concern of how to organize them in files is already outweighed by the need to properly manage them anyway which would lead you to any of the aforementioned libraries.
There's nothing preventing us from adding the suggested support later, but I'd like to start with a very Spring Data consistent way of externalizing queries first collecting further feedback how the transition from that to one of the bespoke libraries went
Jens Schauder commented
As argued by Oliver we should first look at supporting property files as the source for queries.
I created an issue for that: DATAJDBC-234
I'm willing to revisit this at a later point in time when the feature above is available to the public for some time and we have some feedback on it
Toshiaki Maki opened DATAJDBC-230 and commented
It would be useful if we can use a sql file for
@Query
from a view point of maintenancebility.The corresponding sql file will locate at
src/main/resources/com/example/foo/FooRepository/findBySql.sql
as same as MyBatis.In future, it would be great to support template engines for dynamic queries.
Referenced from: pull request https://github.com/spring-projects/spring-data-jdbc/pull/77