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

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