I'm developing an application in java (underlying database is postgresql 9.1) using hibernate 5, hibernate spatial and more technologies.

Previously to my knowledge of the JTS classes to represents coordinates and polylines, I made a custom class to represent a single Latitude and Longitude object: LatLng. To represent polylines, I used List. That became a bad practice when I made use of them, when large objects were made CRUD operations lasted a lot.

So I investigated a bit and found JTS library, which was included within Hibernate Spatial. I realised that my LatLng class could be replaced with Point and polylines List with LineString. That would be an impressive development in performance.

So I get hands on and decided to change my code. I changed the dialect from org.hibernate.dialect.PostgreSQLDialect to org.hibernate.spatial.dialect.postgis.PostgisDialect but maintained the original org.postgresql.Driver driver.

This is an example of one Point attribute within a class, plus it's mapping xml file:

private Point domicilioCoord;
<property name="domicilioCoord" >
    <column name="TRABAJADOR_DOMICILIOCOORD" not-null="false" />

As you can see, there isn't any type attribute within the property tag. If I introduced type="org.hibernate.spatial.JTSGeometryType" (which it'd be the right choice I guess), I got an error saying "Could not instantiate Type: org.hibernate.spatial.JTSGeometryType". I also tried org.hibernate.spatial.GeometryType with the same result. So I decided to remove the type attribute and it worked...

After some inconvenients, I make it work, at least I could initialize the application with no errors. I realised that Point columns were of bytea type in the database, which strikes me a bit.

When retrieving data from the database (data which contains the previously commented Point attr), I get another error. My opinion is that this error is shown due to the lack of an UserType implementor class (which JTSGeometryType and GeometryType are).

I opened a thread on StackOverflow to ask for help.

My question is: how can I map Point and LinearString in hibernate? Is it possible not storing them as bytea?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.