New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@UseFreemarkerSqlLocator is ignored when it comes before @UseFreemarkerEngine #2605
Comments
Thanks for reporting this. I agree in general annotation order should not matter, but in practice I am not sure anyone checks this thoroughly. And, there definitely are some cases where order matters - for example order of registering mappers that can work with some of the same types. We'll see if we can make any improvements here. |
Thanks! I agree about order of registering mappers. It is somewhat expected. Maybe unusual for annotations, but still makes sense to me. But with Offtopic: I think that |
Agree with all of your points. Using the sql locator implying also using the engine seems reasonable to me. |
However, it is not that easy. :-) The problem is not the locator. In fact, you should omit the What happens is that the If you put both annotations in the "wrong" order, then the locator annotation sets the engine correct, then the freemarker annotation (irony alert) overwrites that with the vanilla freemarker engine, which interprets the value of the sql statement annotation as a freemarker template. This is the problem. It is not a bug but a documentation issue. |
Oh, interesting. Sorry for the confusion, then. Based on what you described @hgschmie I assume that If yes, then probably it is possible to automatically check the presense of both and if both are found, throw an exception with a reasonable error message, that explains that these annotations should not be used together? There is also I even remember I previously used
Probably that is why I assumed that |
Currently the ordering of
@UseFreemarkerSqlLocator
and@UseFreemarkerEngine
annotations on a type or a method matters, while I believe it should not.When
@UseFreemarkerEngine
comes before@UseFreemarkerSqlLocator
, then the result is expected: JDBI tries to find a file named{methodName}.sql.ftl
and then tries to useFreemarkerEngine
to build the SQL query.So, this works as expected:
When
@UseFreemarkerEngine
comes after@UseFreemarkerSqlLocator
, then JDBI tries to interpret method name itself as an SQL query, i.e. it ignores@UseFreemarkerSqlLocator
annotation on a method (or on an interface), like it was never present.I believe this is a bug, as logically the order of these annotations should not change the result. Current behavior is very surprising and error-prone.
This code thows an exception:
The only difference is the ordering of
@UseFreemarkerSqlLocator
and@UseFreemarkerEngine
annotations.I created a minimal example with 4 test methods each tests a specific ordering of the annotations on an interface or on a method. You can clone it and run tests. JDBI version used: 3.43.0.
The text was updated successfully, but these errors were encountered: