We upgraded one of our projects to the latest version of Quarkus and encountered a deployment failure in our staging environment with an unusual error message.
Caused by: io.quarkus.runtime.configuration.ConfigurationException: Persistence unit 'default' was configured to run with a database version of at least '10.6.0', but the actual version is '5.5.0'. Consider upgrading your database. Alternatively, rebuild your application with 'quarkus.datasource.db-version=5.5.0' (but this may disable some features and/or impact performance negatively). As a last resort, if you are certain your application will work correctly even though the database version is incorrect, disable the check with 'quarkus.hibernate-orm.database.version-check.enabled=false'
Given that the target database was up-to-date, it was obvious that something else was at fault.
I began by analyzing the stacktrace, working backwards. I quickly discovered that the root cause was in QuarkusRuntimeInitDialectFactory.buildDialect
, where the call to connection.getMetaData().getDatabaseMajorVersion()
returned 5
, rather than the expected 10
for some reason.
At first glance, it wasn’t immediately clear. However, when I repeated the test with the production version, I found that it too returned a detected version of 5
, even if no issues arose from this.
Further investigation revealed that there had been a significant change in QuarkusRuntimeInitDialectFactory::checkActualDbVersion
during one of the intermediate releases.
Through debugging, I proved that in the production version, the flow never entered checkActualDbVersion
, while the branch always did, resulting in the exception. The check is triggered in QuarkusSessionFactoryObserverForDbVersionCheck.sessionFactoryCreated
, which is one of several observers called in SessionFactoryObserverChain.sessionFactoryCreated
.
I could not determine the reason for the incorrect detection of the db version, however, I continued tracing the flow until it reached the point where configuration is loaded.
I found a simple fix: making the dialect explicit in our configuration. This caused versionCheckEnabled
to become false
in QuarkusRuntimeInitDialectFactoryInitiator
(as also mentioned in Quarkus’ docs) and skip checkActualDbVersion
.
In conclusion, the solution was to add this in application.properties
:
quarkus.hibernate-orm.dialect=MariaDB
A solution that is not suggested in the error messages.