Skip to content

Commit

Permalink
Delegate detection of the database version to the Hibernate ORM dialect
Browse files Browse the repository at this point in the history
Because some dialects have very specific ways of detecting the version,
such as running some SQL, that work better than asking the JDBC driver.
  • Loading branch information
yrodiere committed Oct 8, 2024
1 parent 7e4285b commit 55d957b
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,14 @@ public void checkActualDbVersion() {
}

private Optional<DatabaseVersion> retrieveDbVersion(DialectResolutionInfoSource resolutionInfoSource) {
var databaseMetadata = resolutionInfoSource == null ? null
: resolutionInfoSource.getDialectResolutionInfo().getDatabaseMetadata();
if (databaseMetadata == null) {
var resolutionInfo = resolutionInfoSource == null ? null
: resolutionInfoSource.getDialectResolutionInfo();
if (resolutionInfo == null) {
return Optional.empty();
}
try {
triedToRetrieveDbVersion = true;
return Optional.of(DatabaseVersion.make(databaseMetadata.getDatabaseMajorVersion(),
databaseMetadata.getDatabaseMinorVersion()));
return Optional.of(dialect.determineDatabaseVersion(resolutionInfo));
} catch (RuntimeException | SQLException e) {
LOG.warnf(e, "Persistence unit %1$s: Could not retrieve the database version to check it is at least %2$s",
persistenceUnitName, buildTimeDbVersion);
Expand Down

0 comments on commit 55d957b

Please sign in to comment.