Attribute isn't defined error
Hi everyone! I'm doing a query with StringTemplate4 like this:
@SqlUpdate("UPDATE users " +
"<if(first_name)>first_name = :first_name,<endif>" +
"<if(last_name)>last_name = :last_name,<endif>" +
"updated_at = :now WHERE user_id=:id")
@RegisterConstructorMapper(User::class)
@DefineNamedBindings @UseStringTemplateEngine @Timestamped @GetGeneratedKeys
fun update(@Bind("id") id: Int, @BindMap map: Map<String, Any>): User
All runs flawless, but if I don't send "first_name" key, I get this message in console:
attribute first_name isn't defined
Of course, I researched the reason and we need set a new STErrorListener to delete the message, inside this STGroup:
https://github.com/jdbi/jdbi/blob/f3173087f9fbfd3a9c722fe9218fafbea506decd/stringtemplate4/src/main/java/org/jdbi/v3/stringtemplate4/StringTemplateEngine.java#L27
Here's any plan to include this configuration in JDBI? Thanks!
Bindings and defined attributes are separate elements. Bindings are used for data and attributes are for templating.
We have a @DefineBinds annotation that probably does what you want.
@qualidafial can you send me the anchor link please? I can't find it in docs.
BTW, if I remove @DefineNamedBindings my code doesn't work :(
Ok, I didn't read carefully enough the first time. DefineNamedBindings is the annotation name I was looking for.
I think we could accommodate a config option to let you configure an STGroup
Hello Guys,
this ticket is really old and the number of reactions is very low. Therefore, I doubt that there is an urgent need to fix the problem (besides, in the end it is only messy log-noise).
I think we could accommodate a config option to let you configure an STGroup
I guess there is still no such config option. Is there a good way to inject that necessary STErrorListener? The solution offered in this StackOverflow answer is too vague (at least for me).
@mieseprem , please check out #2304 and see if that helps you
Hello @stevenschlansker ! Thanks for having an eye in this ❤️
case NO_SUCH_ATTRIBUTE:
if (!ctx.getConfig(StringTemplates.class).failOnMissingAttribute()) {
break;
}
This part will - as long I don't configure to fail on missing attributes - silently ignore missing attributes. That would indeed mitigate the unnecessary log-noise.