The MyBatis Spring Boot Starter documentation lists properties that can be set in the application.properties file, and that list includes:
configuration: A MyBatis Configuration bean. About available properties see the MyBatis reference page
It's not very obvious from there, but what I think it's suggesting is that you can add something like this:
mybatis.configuration.jdbcTypeForNull=VARCHAR
This seems to work; certainly, if I change VARCHAR
for something that is not a valid value for the enum JdbcType, I get an error. However, it also doesn't appear to be picking up my setting.
When I use a debugger, I can see that MybatisProperties.setConfiguration()
is called, before Configuration.setJdbcTypeForNull()
, which means that the default value (JdbcType.OTHER
) is used instead of the value I'm trying to set.
Am I misunderstanding how this functionality is supposed to be used, or is this a bug? Is anyone else setting config values like this? Elsewhere I can only see examples using XML files, which I'd rather avoid, if possible.
Well, this is embarrassing
I gave up on trying to use the configuration
property in application.properties
, and resorted to the XML config that I was trying to avoid, but just now, having seen some useful suggestions here, I went back to my code, changed it from the XML config back to having mybatis.configuration.jdbcTypeForNull=NULL
and re-ran my test, which was definitely failing under the same conditions before, but now it passes.
I've no idea what's different from before - debugging I see the same behaviour as mentioned above - the Configuration bean seems to get the jdbcTypeForNull parameter set back to OTHER during startup, but then when it's accessed during a query it's NULL again. I'll leave this question here in case it's a race condition and it starts failing again later, but for now my problem seems to have mysteriously disappeared.