diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PGGeometryJdbcType.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PGGeometryJdbcType.java index 3529a36feb..e4feee1f3e 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PGGeometryJdbcType.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PGGeometryJdbcType.java @@ -46,8 +46,6 @@ public class PGGeometryJdbcType implements JdbcType { private final Wkb.Dialect wkbDialect; - // Type descriptor instance using EWKB v1 (postgis versions < 2.2.2) - public static final PGGeometryJdbcType INSTANCE_WKB_1 = new PGGeometryJdbcType( Wkb.Dialect.POSTGIS_EWKB_1 ); // Type descriptor instance using EWKB v2 (postgis versions >= 2.2.2, see: https://trac.osgeo.org/postgis/ticket/3181) public static final PGGeometryJdbcType INSTANCE_WKB_2 = new PGGeometryJdbcType( Wkb.Dialect.POSTGIS_EWKB_2 ); @@ -118,7 +116,7 @@ public class PGGeometryJdbcType implements JdbcType { } private PGobject toPGobject(X value, WrapperOptions options) throws SQLException { - final WkbEncoder encoder = Wkb.newEncoder( Wkb.Dialect.POSTGIS_EWKB_1 ); + final WkbEncoder encoder = Wkb.newEncoder( wkbDialect ); final Geometry geometry = getJavaType().unwrap( value, Geometry.class, options ); final String hexString = encoder.encode( geometry, ByteOrder.NDR ).toString(); final PGobject obj = new PGobject(); diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/dialect/postgis/PostgisUnmarshalTest.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/dialect/postgis/PostgisUnmarshalTest.java index d90ca6294e..c5c86ddff0 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/dialect/postgis/PostgisUnmarshalTest.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/dialect/postgis/PostgisUnmarshalTest.java @@ -69,7 +69,7 @@ public class PostgisUnmarshalTest { public void testCase(String pgValue, Geometry expected) throws SQLException { PGobject pgo = new PGobject(); pgo.setValue( pgValue ); - Geometry received = PGGeometryJdbcType.INSTANCE_WKB_1.toGeometry( pgo ); + Geometry received = PGGeometryJdbcType.INSTANCE_WKB_2.toGeometry( pgo ); assertEquals( String.format( "Failure on %s", pgValue ), expected, received ); } diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/dialect/postgis/hhh14932/TestUsingPostgisWkb221AndLater.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/dialect/postgis/hhh14932/TestUsingPostgisWkb221AndLater.java new file mode 100644 index 0000000000..164ee22725 --- /dev/null +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/dialect/postgis/hhh14932/TestUsingPostgisWkb221AndLater.java @@ -0,0 +1,76 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ + +package org.hibernate.spatial.dialect.postgis.hhh14932; + +import java.util.List; + +import org.hibernate.dialect.PostgreSQLDialect; + +import org.hibernate.testing.RequiresDialect; +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Before; +import org.junit.Test; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import org.geolatte.geom.G2D; +import org.geolatte.geom.Point; + +import static org.geolatte.geom.builder.DSL.point; +import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84; +import static org.junit.Assert.assertEquals; + + +@TestForIssue(jiraKey = "HHH-14932") + +@RequiresDialect(PostgreSQLDialect.class) +public class TestUsingPostgisWkb221AndLater extends BaseCoreFunctionalTestCase { + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { Foo.class }; + } + + @Before + public void setup() { + inTransaction( session -> session.persist( new Foo( + 1, + point( WGS84 ) + ) ) ); + } + + @Test + public void test() { + inTransaction( session -> { + List list = session + .createQuery( "from Foo", Foo.class ) + .getResultList(); + assertEquals( point( WGS84 ), list.get( 0 ).point ); + } ); + } + + @Entity(name = "Foo") + @Table(name = "Foo") + public static class Foo { + @Id + long id; + Point point; + + public Foo() { + } + + public Foo(long id, Point point) { + this.id = id; + this.point = point; + } + + } + +}