From 7329f444b5fd248ee671bb99f260d666c64e2d7e Mon Sep 17 00:00:00 2001 From: Karel Maesen Date: Fri, 18 Jun 2021 13:23:32 +0200 Subject: [PATCH] HHH-14654 Fix for schema validation bug --- .../cockroachdb/CockroachDB202SpatialDialect.java | 5 +++++ .../cockroachdb/CockroachSpatialDialectTrait.java | 5 +++++ .../dialect/postgis/PGSpatialDialectTrait.java | 11 +++++++++++ .../spatial/dialect/postgis/PostgisPG10Dialect.java | 8 ++++++++ .../spatial/dialect/postgis/PostgisPG82Dialect.java | 5 +++++ .../spatial/dialect/postgis/PostgisPG91Dialect.java | 6 ++++++ .../spatial/dialect/postgis/PostgisPG92Dialect.java | 6 ++++++ .../spatial/dialect/postgis/PostgisPG93Dialect.java | 6 ++++++ .../spatial/dialect/postgis/PostgisPG94Dialect.java | 6 ++++++ .../spatial/dialect/postgis/PostgisPG95Dialect.java | 5 +++++ .../spatial/dialect/postgis/PostgisPG9Dialect.java | 6 ++++++ .../spatial/dialect/postgis/PostgisSupport.java | 5 +++++ 12 files changed, 74 insertions(+) diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/cockroachdb/CockroachDB202SpatialDialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/cockroachdb/CockroachDB202SpatialDialect.java index d5ba27617a..31f9927e09 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/cockroachdb/CockroachDB202SpatialDialect.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/cockroachdb/CockroachDB202SpatialDialect.java @@ -42,4 +42,9 @@ public class CockroachDB202SpatialDialect extends CockroachDB201Dialect implemen delegateContributeTypes( typeContributions, serviceRegistry ); } + @Override + public boolean equivalentTypes(int typeCode1, int typeCode2) { + return super.equivalentTypes( typeCode1, typeCode2 ) || + ( isSpatial( typeCode1 ) && isSpatial( typeCode2 ) ); + } } diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/cockroachdb/CockroachSpatialDialectTrait.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/cockroachdb/CockroachSpatialDialectTrait.java index 17ffb69b7e..2df63848ff 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/cockroachdb/CockroachSpatialDialectTrait.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/cockroachdb/CockroachSpatialDialectTrait.java @@ -74,4 +74,9 @@ public interface CockroachSpatialDialectTrait extends SpatialDialect { return DELEGATE.supports( function ); } + + default boolean isSpatial(int typeCode) { + return DELEGATE.isSpatial( typeCode ); + } + } diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PGSpatialDialectTrait.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PGSpatialDialectTrait.java index 2c6dd2edf1..5b7abcd1e1 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PGSpatialDialectTrait.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PGSpatialDialectTrait.java @@ -7,6 +7,8 @@ package org.hibernate.spatial.dialect.postgis; +import java.sql.Types; + import org.hibernate.spatial.SpatialDialect; import org.hibernate.spatial.SpatialFunction; import org.hibernate.spatial.dialect.SpatialFunctionsRegistry; @@ -125,4 +127,13 @@ interface PGSpatialDialectTrait extends SpatialDialect { default boolean supports(SpatialFunction function) { return support.supports( function ); } + + /** + * Checks whether the typeCode is (potentially) the code for a spatial type + * @param typeCode the JDBC type code + * @return if the typecode corresponds with a spatialt type + */ + default boolean isSpatial(int typeCode){ + return support.isSpatial( typeCode ); + } } diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG10Dialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG10Dialect.java index e7c9412b63..1d238bde31 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG10Dialect.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG10Dialect.java @@ -7,6 +7,7 @@ package org.hibernate.spatial.dialect.postgis; +import java.sql.Types; import java.util.Map; import org.hibernate.boot.model.TypeContributions; @@ -36,4 +37,11 @@ public class PostgisPG10Dialect extends PostgreSQL10Dialect implements PGSpatial support.contributeTypes( typeContributions, serviceRegistry ); } + @Override + public boolean equivalentTypes(int typeCode1, int typeCode2) { + return super.equivalentTypes( typeCode1, typeCode2 ) || + ( isSpatial( typeCode1 ) && isSpatial( typeCode2 ) ); + } + + } diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG82Dialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG82Dialect.java index f1fa67c919..9351bceabb 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG82Dialect.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG82Dialect.java @@ -48,6 +48,11 @@ public class PostgisPG82Dialect extends PostgreSQL82Dialect implements SpatialDi support.contributeTypes( typeContributions, serviceRegistry ); } + @Override + public boolean equivalentTypes(int typeCode1, int typeCode2) { + return super.equivalentTypes( typeCode1, typeCode2 ) || + ( support.isSpatial( typeCode1 ) && support.isSpatial( typeCode2 ) ); + } @Override public String getSpatialRelateSQL(String columnName, int spatialRelation) { diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG91Dialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG91Dialect.java index ca871af1df..f2577625f0 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG91Dialect.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG91Dialect.java @@ -48,6 +48,12 @@ public class PostgisPG91Dialect extends PostgreSQL91Dialect implements SpatialDi support.contributeTypes( typeContributions, serviceRegistry ); } + @Override + public boolean equivalentTypes(int typeCode1, int typeCode2) { + return super.equivalentTypes( typeCode1, typeCode2 ) || + ( support.isSpatial( typeCode1 ) && support.isSpatial( typeCode2 ) ); + } + /** * Returns the SQL fragment for the SQL WHERE-clause when parsing * org.hibernatespatial.criterion.SpatialRelateExpressions diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG92Dialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG92Dialect.java index c94d2e9021..e71f982f86 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG92Dialect.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG92Dialect.java @@ -48,6 +48,12 @@ public class PostgisPG92Dialect extends PostgreSQL92Dialect implements SpatialDi support.contributeTypes( typeContributions, serviceRegistry ); } + @Override + public boolean equivalentTypes(int typeCode1, int typeCode2) { + return super.equivalentTypes( typeCode1, typeCode2 ) || + ( support.isSpatial( typeCode1 ) && support.isSpatial( typeCode2 ) ); + } + /** * Returns the SQL fragment for the SQL WHERE-clause when parsing * org.hibernatespatial.criterion.SpatialRelateExpressions diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG93Dialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG93Dialect.java index f8ac29a1a0..ee4ddd9885 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG93Dialect.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG93Dialect.java @@ -48,6 +48,12 @@ public class PostgisPG93Dialect extends PostgreSQL93Dialect implements SpatialDi support.contributeTypes( typeContributions, serviceRegistry ); } + @Override + public boolean equivalentTypes(int typeCode1, int typeCode2) { + return super.equivalentTypes( typeCode1, typeCode2 ) || + ( support.isSpatial( typeCode1 ) && support.isSpatial( typeCode2 ) ); + } + /** * Returns the SQL fragment for the SQL WHERE-clause when parsing * org.hibernatespatial.criterion.SpatialRelateExpressions diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG94Dialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG94Dialect.java index c267cf6d8c..6c14a2afc2 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG94Dialect.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG94Dialect.java @@ -48,6 +48,12 @@ public class PostgisPG94Dialect extends PostgreSQL94Dialect implements SpatialDi support.contributeTypes( typeContributions, serviceRegistry ); } + @Override + public boolean equivalentTypes(int typeCode1, int typeCode2) { + return super.equivalentTypes( typeCode1, typeCode2 ) || + ( support.isSpatial( typeCode1 ) && support.isSpatial( typeCode2 ) ); + } + /** * Returns the SQL fragment for the SQL WHERE-clause when parsing * org.hibernatespatial.criterion.SpatialRelateExpressions diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG95Dialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG95Dialect.java index 118584fac2..1c31d221ad 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG95Dialect.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG95Dialect.java @@ -42,4 +42,9 @@ public class PostgisPG95Dialect extends PostgreSQL95Dialect implements PGSpatial support.contributeTypes( typeContributions, serviceRegistry ); } + @Override + public boolean equivalentTypes(int typeCode1, int typeCode2) { + return super.equivalentTypes( typeCode1, typeCode2 ) || + ( isSpatial( typeCode1 ) && isSpatial( typeCode2 ) ); + } } diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG9Dialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG9Dialect.java index 9182f947f0..88fefa5205 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG9Dialect.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG9Dialect.java @@ -48,6 +48,12 @@ public class PostgisPG9Dialect extends PostgreSQL9Dialect implements SpatialDial support.contributeTypes( typeContributions, serviceRegistry ); } + @Override + public boolean equivalentTypes(int typeCode1, int typeCode2) { + return super.equivalentTypes( typeCode1, typeCode2 ) || + ( support.isSpatial( typeCode1 ) && support.isSpatial( typeCode2 ) ); + } + /** * Returns the SQL fragment for the SQL WHERE-clause when parsing * org.hibernatespatial.criterion.SpatialRelateExpressions diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisSupport.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisSupport.java index 126a86e072..ef361f47f5 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisSupport.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisSupport.java @@ -7,6 +7,7 @@ package org.hibernate.spatial.dialect.postgis; import java.io.Serializable; +import java.sql.Types; import org.hibernate.boot.model.TypeContributions; import org.hibernate.service.ServiceRegistry; @@ -47,6 +48,10 @@ public class PostgisSupport implements SpatialDialect, Serializable { return postgisFunctions; } + public boolean isSpatial(int typeCode){ + return typeCode == Types.OTHER || typeCode == PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(); + } + /** * Returns the SQL fragment for the SQL WHERE-clause when parsing * org.hibernatespatial.criterion.SpatialRelateExpressions