diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BindMaxLength.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BindMaxLength.java index 51bdcfa1a6..dcc4e4428d 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BindMaxLength.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BindMaxLength.java @@ -37,23 +37,29 @@ final class UTF8 implements BindMaxLength { public long length(int dbLength, Object obj) { if (obj instanceof String) { String s = (String) obj; - int stringLength = s.length(); - if (stringLength > dbLength) { - return stringLength; - } else if (stringLength * 4 <= dbLength) { - return -1; - } else { - return s.getBytes(StandardCharsets.UTF_8).length; - } - + return utf8String(dbLength, s); } else if (obj instanceof byte[]) { return ((byte[]) obj).length; } else if (obj instanceof InputStreamInfo) { return ((InputStreamInfo) obj).length(); + } else if ("org.postgresql.util.PGobject".equals(obj.getClass().getCanonicalName())) { + String value = ((org.postgresql.util.PGobject) obj).getValue(); + return value == null ? -1 : utf8String(dbLength, value); } else { return -1; } } + + private static int utf8String(int dbLength, String s) { + int stringLength = s.length(); + if (stringLength > dbLength) { + return stringLength; + } else if (stringLength * 4 <= dbLength) { + return -1; + } else { + return s.getBytes(StandardCharsets.UTF_8).length; + } + } } /** @@ -69,6 +75,9 @@ public long length(int dbLength, Object obj) { return ((byte[]) obj).length; } else if (obj instanceof InputStreamInfo) { return ((InputStreamInfo) obj).length(); + } else if ("org.postgresql.util.PGobject".equals(obj.getClass().getCanonicalName())) { + String value = ((org.postgresql.util.PGobject) obj).getValue(); + return value == null ? -1 : value.length(); } else { return -1; } diff --git a/ebean-test/src/test/resources/ebean.properties b/ebean-test/src/test/resources/ebean.properties index 9dec823eed..6bd984585f 100644 --- a/ebean-test/src/test/resources/ebean.properties +++ b/ebean-test/src/test/resources/ebean.properties @@ -157,6 +157,7 @@ datasource.oracle.url=jdbc:oracle:thin:@localhost:1521:XE ## set this to use timestamp rather than timestamptz #ebean.postgres.timestamp=timestamp +ebean.pg.lengthCheck=on datasource.pg.username=unit datasource.pg.password=test datasource.pg.url=jdbc:postgresql://127.0.0.1:6432/unit diff --git a/ebean-test/testconfig/ebean-cockroach.properties b/ebean-test/testconfig/ebean-cockroach.properties index 604387b760..f088b32601 100644 --- a/ebean-test/testconfig/ebean-cockroach.properties +++ b/ebean-test/testconfig/ebean-cockroach.properties @@ -2,4 +2,4 @@ ebean.test.platform=cockroach ebean.test.dbName=unit datasource.default=cockroach #ebean.test.cockroach.version=v21.2.6 - +ebean.lengthCheck=on diff --git a/ebean-test/testconfig/ebean-postgres.properties b/ebean-test/testconfig/ebean-postgres.properties index 35a8bbbdab..f87670982d 100644 --- a/ebean-test/testconfig/ebean-postgres.properties +++ b/ebean-test/testconfig/ebean-postgres.properties @@ -2,4 +2,4 @@ ebean.test.platform=postgres datasource.default=postgres ebean.test.dbName=unit ebean.test.postgres.version=15 - +ebean.lengthCheck=on diff --git a/ebean-test/testconfig/ebean-yugabyte.properties b/ebean-test/testconfig/ebean-yugabyte.properties index 2b8e462cca..f5befb1ac2 100644 --- a/ebean-test/testconfig/ebean-yugabyte.properties +++ b/ebean-test/testconfig/ebean-yugabyte.properties @@ -2,4 +2,4 @@ ebean.test.platform=yugabyte datasource.default=yugabyte ebean.test.dbName=unit ebean.test.yugabyte.version=2.18.0.0-b65 - +ebean.lengthCheck=on