javamysqlhibernatehibernate-spatial

Mapping MySQL Point Data Type with Hibernate


I have an existing MySQL database with a column in a table that has a "point" data type. The first thing I did was add the spatial dependency to our gradle build file via:

implementation 'org.hibernate:hibernate-spatial:5.4.2.Final'

I'm struggling to figure out exactly how to modify our mapping file (it's XML based, not using annotations) and the corresponding model to support loading this.

    <property name="pickupLocation" type="???">
        <column name="pickup_location" sql-type="???"/>
    </property>

From what I've gathered in the small subset of examples I can find online, I need it to end up in a: com.vividsolutions.jts.geom.Point data type in my model. That's essentially all I have on the model end. I would assume that sql-type should just be "point", but recognize that might be an inaccurate assumption. No matter what combination of types/sql-types I try, I generally end up with a deserialization error in an obscure stack trace that's not particularly helpful.

If it's relevant, I seeded the data in the table via: SET pickup_location=POINT(18 -63).


Solution

  • As long as pickupLocation is of type JTS Point, no type or sql-type should be necessary in the mapping file.

    You may want to check that your application is actually using a Spatial Dialect (see the manual for available dialects). It is the most common source for this type of problem.

    In any case, the value point is correct for sql-type, and for type it should be jts_geometry.