From 411846347b56a5bfd8fc4a9ce90a500d77e25228 Mon Sep 17 00:00:00 2001 From: Robin Bygrave Date: Thu, 7 Jul 2016 21:33:19 +1200 Subject: [PATCH] #762 - Change H2 Platform to IDENTITY (from SEQUENCE) with version 1.4.192 --- pom.xml | 2 +- .../avaje/ebean/config/dbplatform/H2Platform.java | 14 +++++++++++--- src/test/resources/ebean.properties | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 7e96ac76e..091e2d30d 100644 --- a/pom.xml +++ b/pom.xml @@ -177,7 +177,7 @@ com.h2database h2 - 1.4.189 + 1.4.192 provided diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/H2Platform.java b/src/main/java/com/avaje/ebean/config/dbplatform/H2Platform.java index c406558d9..ae44bd34f 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/H2Platform.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/H2Platform.java @@ -4,6 +4,7 @@ import com.avaje.ebean.BackgroundExecutor; import com.avaje.ebean.dbmigration.ddlgeneration.platform.H2Ddl; import javax.sql.DataSource; +import java.util.Properties; /** * H2 specific platform. @@ -19,9 +20,7 @@ public class H2Platform extends DatabasePlatform { this.nativeUuidType = true; this.dbDefaultValue.setNow("now()"); - // only support getGeneratedKeys with non-batch JDBC - // so generally use SEQUENCE instead of IDENTITY for H2 - this.dbIdentity.setIdType(IdType.SEQUENCE); + this.dbIdentity.setIdType(IdType.IDENTITY); this.dbIdentity.setSupportsGetGeneratedKeys(true); this.dbIdentity.setSupportsSequence(true); this.dbIdentity.setSupportsIdentity(true); @@ -34,6 +33,15 @@ public class H2Platform extends DatabasePlatform { // so no changes to dbTypeMap required } + @Override + public void configure(Properties properties) { + super.configure(properties); + String idType = properties.getProperty("ebean.h2.idtype"); + if (idType != null) { + this.dbIdentity.setIdType(IdType.valueOf(idType)); + } + } + /** * Return a H2 specific sequence IdGenerator that supports batch fetching * sequence values. diff --git a/src/test/resources/ebean.properties b/src/test/resources/ebean.properties index 28c472181..8eb6e2842 100644 --- a/src/test/resources/ebean.properties +++ b/src/test/resources/ebean.properties @@ -21,6 +21,8 @@ datasource.default=h2 #ebean.persistBatch=NONE +#ebean.h2.idType=SEQUENCE + ebean.currentUserProvider=com.avaje.ebean.MyCurrentUserProvider #ebean.expressionNativeIlike=true #ebean.jsonInclude=NON_NULL