Hibernate Spatial cannot parse boxes from PostGIS

Description

We encountered a problem using the PostGIS function st_extent or extent. Since version 5 Hibernate Spatial seems to be unable to parse boxes and throws the follwoing error:

java.lang.NumberFormatException: For input string: "BO"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at org.geolatte.geom.ByteBuffer.from(ByteBuffer.java:78)
at org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor.toGeometry(PGGeometryTypeDescriptor.java:116)
at org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor$2.doExtract(PGGeometryTypeDescriptor.java:88)
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:258)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:254)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:244)
at org.hibernate.loader.hql.QueryLoader.getResultRow(QueryLoader.java:453)

The 'BO' comes from BOX(33321440 5979576.8,33321692.8 5979767.2). In PGGeometryTypeDescriptor#toGeometry it will try to parse the result either as WKT or WKB. As a box is not a valid WKT type it will try to parse it as a WKB. As far as I understand it, we would need a third branch handling boxes specifically.

In our case we had to re-register the function extent as st_extent to make it work with PostGIS 2.0. I know that it is not supported by Hibernate Spatial yet, but as the documentation states the return type of extent in PostGIS 1.3 is a BOX3D. Therefore this problems seems to be more general to me.
The code in question is:

PGGeometryTypeDescriptor#toGeometry

Environment

Hibernate 5.2.2, PostGIS 2.1

Activity

Show:
Karel Maesen
October 29, 2016, 2:23 PM

I fixed this in the master branch.

I changed the function name to 'st_extent' and added a geometry cast at the end. So the extent function in HQL will now always return a geometry object (POINT or POLYGON).

Could you check whether this resolves all issues?

Btw, we support Postgis 2.x, just not all of its features.

Marko Skočibušić
November 2, 2016, 2:37 PM

Yes, this seems to fix the problem. Thank you very much.

Gail Badner
February 28, 2017, 7:21 AM

Re-opening to remove 5.1.next as a fix version.

Gail Badner
February 28, 2017, 7:50 AM

, we are no longer releasing 5.0 or 5.1 versions, so I am reverting your commits to 5.1 and removing 5.1.next as a fix version.

Assignee

Karel Maesen

Reporter

Marko Skočibušić

Fix versions

Labels

None

backPortable

Backport?

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure