diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cleaner/PostgreSQLDatabaseCleaner.java b/hibernate-testing/src/main/java/org/hibernate/testing/cleaner/PostgreSQLDatabaseCleaner.java index 567b05f456..d7d758527a 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cleaner/PostgreSQLDatabaseCleaner.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cleaner/PostgreSQLDatabaseCleaner.java @@ -31,7 +31,8 @@ public class PostgreSQLDatabaseCleaner implements DatabaseCleaner { @Override public boolean isApplicable(Connection connection) { try { - return connection.getMetaData().getDatabaseProductName().startsWith( "PostgreSQL" ); + return connection.getMetaData().getDatabaseProductName().startsWith( "PostgreSQL" ) + && isPostgresql( connection ); } catch (SQLException e) { throw new RuntimeException( "Could not resolve the database metadata!", e ); @@ -211,4 +212,19 @@ public class PostgreSQLDatabaseCleaner implements DatabaseCleaner { } } + // We need this check to differentiate between Postgresql and Cockroachdb + private boolean isPostgresql(Connection connection) { + try (Statement stmt = connection.createStatement()) { + ResultSet rs = stmt.executeQuery( "select version() " ); + while ( rs.next() ) { + String version = rs.getString( 1 ); + return version.contains( "PostgreSQL" ); + } + } + catch (SQLException e) { + throw new RuntimeException( e ); + } + return false; + } + }