问题
I'm building a small Geo server using PostgreSQL + PostGIS + Grails 4 + Geoserver + React + JTS. The domain class has a com.vividsolutions.jts.geom.Point
field that is maped to a sqlType: 'geometry(Point,4326)'
. When I search any findBy...(...)
search, I cannot get the result, as it is not posible deserialize
in Grails 2.x I did not get this problem. It's my first time programming in Grails in 3 years.
package ....
import com.vividsolutions.jts.geom.Point
class Aqop {
String pid
String pname
Float x
Float y
String srid
Point center
static mapping = {
table 'aqop'
version false
autoTimestamp false
cache true
id column: 'aqop_id'
pname column: 'pname', type: 'text', index: 'aqop_pname_idx'
pid column: 'pid', type: 'text', index: 'aqop_pid_idx'
x column: 'x'
y column: 'y'
srid column: 'srid', type: 'text'
center column: 'center', sqlType: 'geometry(Point,4326)'
}
static constraints = {
pname size: 1..128, unique: true
pid size: 1..64, unique: true
x nullable: false
y nullable: false
srid nullable: false, size: 1..64
}
}
This the error message:
org.hibernate.type.SerializationException: could not deserialize
at org.hibernate.internal.util.SerializationHelper.doDeserialize(SerializationHelper.java:243)
at org.hibernate.internal.util.SerializationHelper.deserialize(SerializationHelper.java:287)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.fromBytes(SerializableTypeDescriptor.java:138)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:113)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:29)
at org.hibernate.type.descriptor.sql.VarbinaryTypeDescriptor$2.doExtract(VarbinaryTypeDescriptor.java:60)
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:261)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:257)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:247)
at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:333)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:3018)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1752)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1678)
at org.hibernate.loader.Loader.getRow(Loader.java:1567)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:731)
at org.hibernate.loader.Loader.processResultSet(Loader.java:990)
at org.hibernate.loader.Loader.doQuery(Loader.java:948)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340)
at org.hibernate.loader.Loader.doList(Loader.java:2695)
at org.hibernate.loader.Loader.doList(Loader.java:2678)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2512)
at org.hibernate.loader.Loader.list(Loader.java:2507)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1972)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:370)
at org.grails.orm.hibernate.query.AbstractHibernateQuery.singleResultViaListCall(AbstractHibernateQuery.java:807)
at org.grails.orm.hibernate.query.AbstractHibernateQuery.singleResult(AbstractHibernateQuery.java:794)
at org.grails.datastore.gorm.finders.AbstractFindByFinder.invokeQuery(AbstractFindByFinder.java:35)
at org.grails.datastore.gorm.finders.AbstractFindByFinder$1.doInSession(AbstractFindByFinder.java:29)
at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:319)
at org.grails.datastore.gorm.finders.AbstractFinder.execute(AbstractFinder.java:42)
....
How camn I get deserialized the Domain Object ? Any help is welcome and thanks in advance.
回答1:
According to documentation Grails 4 is compatible with latest version of Hibernate 5.4.
Karel Maesen in linked issue comments that latest versions of Hibernate expect latest versions of JTS.
Migrate your dependency from vividsolutions.jts
to locationtech.jts
and define Point
as org.locationtech.jts.geom.Point
More info: https://github.com/locationtech/jts
来源:https://stackoverflow.com/questions/57384610/how-to-get-deserialized-jts-geometry-field-in-grails-4