0

Code first:

PGpoint coordinates = (PGpoint) rs.getObject(4);

Causes ClassCastException.

Referencing postgresql-9.1-901.jdbc3.jar on the project.

Returning a recordset on a android application. Any way to circumvent this?

TIA

  • Basically: `rs.getObject(4);` is a `PGObject`, not a `PGPoint`. – assylias Apr 21 '12 at 21:56
  • Thx for the input assylias. Could you be so kind as to elaborate? Because for me PGPoint is a descendant of PGObject ... :) – Pedro Doria Meunier Apr 21 '12 at 22:01
  • 1
    If you want us to eleborate, you should provide us with more information. Does it happen sometimes? With all PGxxx objects? Why do you _expect_ it to be a PGpoint? etc. – Paul-Jan Apr 22 '12 at 05:31
  • @user1214454 let's imagine that your PGObject is a PGbox, it is not a PGPoint and the line you show would throw that kind of Exception. – assylias Apr 22 '12 at 07:55
  • you can create a custom type in order to support it https://stackoverflow.com/questions/53548731/how-to-work-with-pgpoint-for-geolocation-using-postgresql – Jonathan JOhx Dec 13 '18 at 04:13

1 Answers1

0

This looks very similar to the question org.postgresql.util.PGobject cannot be cast to org.postgis.PGgeometry. The answer provided there, quoted below, mentions postgis.jar being not installed property. Might this apply to your situation as well? How did you install postgis?

If you use Hibernate Spatial in a web container with the JDBC provided by the container through JNDI, then the postgis.jar should also be installed together with the JDBC driver and should not be contained in the WEB-INF/lib directory

Community
  • 1
  • 1
Paul-Jan
  • 16,746
  • 1
  • 63
  • 95
  • Hi Paul-Jan. No, I don't use Hibernate. As to clarify my question, I do expect it to be a POINT since it's enforced at table-level. CONSTRAINT enforce_dims_geometry CHECK (ndims(geometry) = 2) So, in a nutshell, it's a postgis-enabled database. Must I add postgis.jar to the external libraries in my project? If so, what's the correct way of accessing geometry of the type POINT via a resultset? TIA. – Pedro Doria Meunier Apr 22 '12 at 07:59