How do I map a 'Geography(POINT, 4326)' type?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I map a 'Geography(POINT, 4326)' type?

Approche Pratique
Hi,

I have some data in 'Geography(POINT, 4326)' format and I'd like to keep them that way. I want to access that data using Hibernate / Spring JPA

I've so far tried:
a. Map them as byte[]:

@Column(columnDefinition="geography(POINT, 4326)")
private byte[] location;

This leads to:
org.postgresql.util.PSQLException: ERROR: Invalid endian flag value encountered.
as described here:

http://stackoverflow.com/questions/24240534/mapping-geography-to-byte-psqlexception-invalid-endian-flag-value-encountere

Also, the bytes it reads from database don't seem to have any relation to how PostgreSQL shows the column in pgAdmin, and parsing them using:

new WKBReader(new GeometryFactory(new PrecisionModel(), WGS84_SRID)).read(bytes)

fails with "com.vividsolutions.jts.io.ParseException: Unknown WKB type 48".


b. Map them as org.postgis.PGgeometry

  @Type(type = "org.hibernate.spatial.GeometryType")
    @Column(columnDefinition="geography(POINT, 4326)")
    private PGgeometry location;

This leads to:

java.lang.IllegalArgumentException: Can't convert object of type org.postgresql.util.PGobject
    at org.hibernate.spatial.dialect.postgis.PGGeometryValueExtractor.toJTS(PGGeometryValueExtractor.java:113)
    at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.doExtract(AbstractJTSGeometryValueExtractor.java:50)
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:263)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:259)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:249)
    at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:334)
    at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2969)
    at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1695)


I'm using Hibernate Core (4.3.1.Final), hibernate-spatial-4.3-SNAPSHOT (I needed SNAPSHOT for some other issue I ran into with 'org.hibernate.spatial.dialect.postgis.PostgisDialect' as dialect), with PostgreSQL JDBC driver 9.3-1101-jdbc41 and PostgreSQL 9.3 database w/ PostGIS 2.1.3 on Windows 7 64-bit.

Any ideas what I'm doing wrong?

Is there a standard documented solution for this?

Regards,
John


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: How do I map a 'Geography(POINT, 4326)' type?

Approche Pratique
I should have mentioned - I also tried:

c) Mapping to com.vividsolutions.jts.geom.Point as per tutorial:

    @Type(type = "org.hibernate.spatial.GeometryType")
    @Column(columnDefinition="geography(POINT, 4326)")
    private Point location;


With same results as b.:

type org.postgresql.util.PGobject; nested exception is java.lang.IllegalArgumentException: Can't convert object of type org.postgresql.util.PGobject] with root cause

java.lang.IllegalArgumentException: Can't convert object of type org.postgresql.util.PGobject
    at org.hibernate.spatial.dialect.postgis.PGGeometryValueExtractor.toJTS(PGGeometryValueExtractor.java:113)
    at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.doExtract(AbstractJTSGeometryValueExtractor.java:50)


Regards,
John


On Mon, Jun 16, 2014 at 4:51 PM, Approche Pratique <[hidden email]> wrote:
Hi,

I have some data in 'Geography(POINT, 4326)' format and I'd like to keep them that way. I want to access that data using Hibernate / Spring JPA

I've so far tried:
a. Map them as byte[]:

@Column(columnDefinition="geography(POINT, 4326)")
private byte[] location;

This leads to:
org.postgresql.util.PSQLException: ERROR: Invalid endian flag value encountered.
as described here:

http://stackoverflow.com/questions/24240534/mapping-geography-to-byte-psqlexception-invalid-endian-flag-value-encountere

Also, the bytes it reads from database don't seem to have any relation to how PostgreSQL shows the column in pgAdmin, and parsing them using:

new WKBReader(new GeometryFactory(new PrecisionModel(), WGS84_SRID)).read(bytes)

fails with "com.vividsolutions.jts.io.ParseException: Unknown WKB type 48".


b. Map them as org.postgis.PGgeometry

  @Type(type = "org.hibernate.spatial.GeometryType")
    @Column(columnDefinition="geography(POINT, 4326)")
    private PGgeometry location;

This leads to:

java.lang.IllegalArgumentException: Can't convert object of type org.postgresql.util.PGobject
    at org.hibernate.spatial.dialect.postgis.PGGeometryValueExtractor.toJTS(PGGeometryValueExtractor.java:113)
    at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.doExtract(AbstractJTSGeometryValueExtractor.java:50)
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:263)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:259)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:249)
    at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:334)
    at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2969)
    at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1695)


I'm using Hibernate Core (4.3.1.Final), hibernate-spatial-4.3-SNAPSHOT (I needed SNAPSHOT for some other issue I ran into with 'org.hibernate.spatial.dialect.postgis.PostgisDialect' as dialect), with PostgreSQL JDBC driver 9.3-1101-jdbc41 and PostgreSQL 9.3 database w/ PostGIS 2.1.3 on Windows 7 64-bit.

Any ideas what I'm doing wrong?

Is there a standard documented solution for this?

Regards,
John



_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: How do I map a 'Geography(POINT, 4326)' type?

Karel Maesen
Administrator
Hello John,


Attempt c) - setting type to o.h.s.GeometryType is the only correct mapping.

Currently, Hibernate Spatial doesn’t support the Geography type. The postgres/postgis JDBC driver doesn’t return a PGgeometry object for Geographies, and that triggers the error. I’m afraid that the only work-around is converting the type from geography to geometry.

Support for Geographies is coming in Hibernate 5.

Regards,

Karel


On 16 Jun 2014, at 18:01, Approche Pratique <[hidden email]> wrote:

> I should have mentioned - I also tried:
>
> c) Mapping to com.vividsolutions.jts.geom.Point as per tutorial:
>
>     @Type(type = "org.hibernate.spatial.GeometryType")
>     @Column(columnDefinition="geography(POINT, 4326)")
>     private Point location;
>
>
> With same results as b.:
>
> type org.postgresql.util.PGobject; nested exception is java.lang.IllegalArgumentException: Can't convert object of type org.postgresql.util.PGobject] with root cause
>
> java.lang.IllegalArgumentException: Can't convert object of type org.postgresql.util.PGobject
>     at org.hibernate.spatial.dialect.postgis.PGGeometryValueExtractor.toJTS(PGGeometryValueExtractor.java:113)
>     at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.doExtract(AbstractJTSGeometryValueExtractor.java:50)
>
>
> Regards,
> John
>
>
> On Mon, Jun 16, 2014 at 4:51 PM, Approche Pratique <[hidden email]> wrote:
> Hi,
>
> I have some data in 'Geography(POINT, 4326)' format and I'd like to keep them that way. I want to access that data using Hibernate / Spring JPA
>
> I've so far tried:
> a. Map them as byte[]:
>
> @Column(columnDefinition="geography(POINT, 4326)")
>
> private byte
> [] location;
>
> This leads to:
> org.postgresql.util.PSQLException: ERROR: Invalid endian flag value encountered.
>
>
>
> as described here:
>
> http://stackoverflow.com/questions/24240534/mapping-geography-to-byte-psqlexception-invalid-endian-flag-value-encountere
>
> Also, the bytes it reads from database don't seem to have any relation to how PostgreSQL shows the column in pgAdmin, and parsing them using:
>
> new WKBReader(new GeometryFactory(new PrecisionModel(), WGS84_SRID)).read(bytes)
>
> fails with "com.vividsolutions.jts.io.ParseException: Unknown WKB type 48".
>
>
> b. Map them as org.postgis.PGgeometry
>
>   @Type(type = "org.hibernate.spatial.GeometryType")
>     @Column(columnDefinition="geography(POINT, 4326)")
>     private PGgeometry location;
>
> This leads to:
>
> java.lang.IllegalArgumentException: Can't convert object of type org.postgresql.util.PGobject
>     at org.hibernate.spatial.dialect.postgis.PGGeometryValueExtractor.toJTS(PGGeometryValueExtractor.java:113)
>     at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.doExtract(AbstractJTSGeometryValueExtractor.java:50)
>     at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
>     at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:263)
>     at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:259)
>     at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:249)
>     at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:334)
>     at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2969)
>     at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1695)
>
>
> I'm using Hibernate Core (4.3.1.Final), hibernate-spatial-4.3-SNAPSHOT (I needed SNAPSHOT for some other issue I ran into with 'org.hibernate.spatial.dialect.postgis.PostgisDialect' as dialect), with PostgreSQL JDBC driver 9.3-1101-jdbc41 and PostgreSQL 9.3 database w/ PostGIS 2.1.3 on Windows 7 64-bit.
>
> Any ideas what I'm doing wrong?
>
> Is there a standard documented solution for this?
>
> Regards,
> John
>
>
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: How do I map a 'Geography(POINT, 4326)' type?

Approche Pratique
In reply to this post by Approche Pratique
Karel,

Thank you for your response.

I moved to storing it as Geometry in the database and it helped.

Regards,
John


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users