diff --git a/platforms/postgres/pom.xml b/platforms/postgres/pom.xml
index e2c37fae0..57a6a73e8 100644
--- a/platforms/postgres/pom.xml
+++ b/platforms/postgres/pom.xml
@@ -17,6 +17,20 @@
13.10.1-SNAPSHOT
+
+ io.ebean
+ ebean-test-containers
+ 6.3
+ test
+
+
+
+ org.postgresql
+ postgresql
+ 42.5.0
+ test
+
+
io.avaje
junit
diff --git a/platforms/postgres/src/main/java/io/ebean/platform/postgres/PostgresPlatformProvider.java b/platforms/postgres/src/main/java/io/ebean/platform/postgres/PostgresPlatformProvider.java
index 86c65ab65..96d0b223f 100644
--- a/platforms/postgres/src/main/java/io/ebean/platform/postgres/PostgresPlatformProvider.java
+++ b/platforms/postgres/src/main/java/io/ebean/platform/postgres/PostgresPlatformProvider.java
@@ -62,7 +62,9 @@ public class PostgresPlatformProvider implements DatabasePlatformProvider {
}
}
} finally {
- connection.rollback();
+ if (!connection.getAutoCommit()) {
+ connection.rollback();
+ }
}
if (majorVersion <= 9) {
return new Postgres9Platform();
diff --git a/platforms/postgres/src/test/java/io/ebean/platform/postgres/PostgresPlatformTest.java b/platforms/postgres/src/test/java/io/ebean/platform/postgres/PostgresPlatformTest.java
index 7fe897f40..e9a604c82 100644
--- a/platforms/postgres/src/test/java/io/ebean/platform/postgres/PostgresPlatformTest.java
+++ b/platforms/postgres/src/test/java/io/ebean/platform/postgres/PostgresPlatformTest.java
@@ -5,8 +5,14 @@ import io.ebean.config.PlatformConfig;
import io.ebean.config.dbplatform.DatabasePlatform;
import io.ebean.config.dbplatform.DbPlatformType;
import io.ebean.config.dbplatform.DbType;
+import io.ebean.test.containers.PostgresContainer;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+
import static io.ebean.Query.LockType.*;
import static io.ebean.Query.LockWait.*;
import static org.assertj.core.api.Assertions.assertThat;
@@ -14,6 +20,38 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
class PostgresPlatformTest {
+ /**
+ * Let's just run this test manually.
+ */
+ @Disabled
+ @Test
+ void platformDetection() throws SQLException {
+ PostgresContainer container = PostgresContainer.builder("15")
+ .containerName("pg15_ebeanTest")
+ .dbName("unit")
+ .port(0) // use a random port
+ .build();
+
+ container.startWithDropCreate();
+
+ try (Connection connection = container.createConnection()) {
+ connection.setAutoCommit(true);
+ DatabaseMetaData metaData = connection.getMetaData();
+
+ PostgresPlatformProvider platformProvider = new PostgresPlatformProvider();
+
+ DatabasePlatform platform = platformProvider.create(15, 0, metaData, connection);
+ assertThat(platform.name()).isEqualTo("postgres");
+
+ connection.setAutoCommit(false);
+ DatabasePlatform platform2 = platformProvider.create(15, 0, metaData, connection);
+ assertThat(platform2.name()).isEqualTo("postgres");
+
+ } finally {
+ container.stopRemove();
+ }
+ }
+
@Test
void testUuidType() {
PostgresPlatform platform = new PostgresPlatform();