Closed p91paul closed 2 weeks ago
@p91paul
I'm not much of an expert in quarkus, but if I recollected information correctly @Record(ExecutionTime.STATIC_INIT) means that this action is executed at compile/build time, and not at runtime.
Yeah, but it only impacts the native mode. Did you try to alter it to @Record(ExecutionTime.RUNTIME_INIT)
to see if it works?
Can you provide a simple test for databaseId
and it will be helpful when we consider the solution?
Basicly, I'm think to have our implementation of DatabaseIdProvider
to provide the databaseId
based on the config from application.properties
I've built a reproducer project; you'll see it fails to start both during tests and normal run in dev mode, because it will try to resolve databaseId before the agroal data source is created. I believe this is a side effect of this being a builditem (even without native compilation, these are executed before the application actually starts, are they not?)
demo-mybatis-quarkus-databaseid.zip
The example is based on what mybatis documentation suggests you should be doing, which is more flexible because it's a runtime check; but as stated earlier, having a DatabaseIdProvider that reads from application.properties would be good enough for me!
Thanks @p91paul - I will check your reproducer asap.
@p91paul I just release 2.2.4
to include this fix.
I created the following mybatis-config.xml
That configuration is read from https://github.com/quarkiverse/quarkus-mybatis/blob/77f203db6e26787e43bbf7d0726b567a70034a56/mybatis/deployment/src/main/java/io/quarkiverse/mybatis/deployment/MyBatisProcessor.java#L246
I'm not much of an expert in quarkus, but if I recollected information correctly
@Record(ExecutionTime.STATIC_INIT)
means that this action is executed at compile/build time, and not at runtime. This breaks thedatabaseIdProvider
config, which by default opens a connection to the database, checks the connection metadata and determines the running database. Only after that mybatis can actually parse the mappers xml files, and resolve the correct query based on the databaseId.See
I do not know if this is fixable with an option to create the session factory at runtime, and to do so only after the agroal extension did her work and created the actual datasource.
As an alternative, for my use case it would be enough for me to have a way to configure the databaseId at compile time without using a provider, e.g. to put something like this in application.properties:
This would be even better for me, because I do not need xml config at all (I only tried to use it to specify the databaseId provider)