| It works with hibernate-spatial and just a field because hibernate-spatial has done all of the integration work for you. Specifically e.g. take a look at the HANA spatial dialect:
- You can see that it registers 2 custom SqlTypeDescriptors (HANAGeometryTypeDescriptor and HANAPointTypeDescriptor) - SqlTypeDescriptors are a Hibernate contract used to provide additional information about JDBC type. {hibernate-core understands the basic ones like Types.INTEGER, etc.
- It also registers a number of Hibernate Type implementations (GeolatteGeometryType and JTSGeometryType). These are actually the things that make the attribute @Type work. And actually you could even leave off the @Type. Hibernate would still recognize it properly - provided the exposed type is the geolatte type.
- "Underneath the covers" it also registers the JavaTypeDescriptor for Geometry.
It does not work with AttributeConverter simply because the resolution of "relational Java type" (Geometry) to corresponding JDBC type code is statically defined in that JdbcTypeJavaClassMappings I mentioned. Hibernate sees Geometry as the "relational Java type" for your converter and tries to use JdbcTypeJavaClassMappings to determine its JDBC type code - but of course JdbcTypeJavaClassMappings does not know that mapping. So it basically makes a wild guess using the Geometry Class's hashCode. Hence why I asked you to try a patched JdbcTypeJavaClassMappings. As for the JavaTypeDescriptor, you do not have to register a descriptor for your custom Java type(s). However, just take a look at the API and you can see the kinds of things it lets you tell Hibernate about the type, generally for some performance gain of some kind.
So, if I add the mapping for Geolatte's Point to hibernate-core, do I still need to depend on hibernate-spatial? And then, should I still use the JPA's AttributeConverter or do I need to use a Hibernate's JavaTypeDescriptor instead?
You can use either. But unfortunately Hibernate cannot currently handle AttributeConverters with non-standard "relational Java type". So for this use specifically you will either need to patch JdbcTypeJavaClassMappings or use Geometry in your domain model and rely on spatial's classes. I think spatial's types rely on spatial being used though. Karel Maesen would be better able to answer that |