我正在使用PostgreSQL + PostGIS + Grails 4 + Geoserver + React + JTS构建小型Geo服务器。域类具有一个com.vividsolutions.jts.geom.Point
字段,该字段映射到sqlType: 'geometry(Point,4326)'
。当我搜索任何findBy...(...)
搜索时,我无法获得结果,因为它不是可能的deserialize
在Grails 2.x中,我没有遇到这个问题。这是我三年来第一次在Grails中编程。
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
}
}
这是错误信息:
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)
....
我如何反序列化域对象?欢迎任何帮助,并在此先感谢。
最佳答案
根据documentation的说明,Grails 4与最新版本的Hibernate 5.4兼容。
Karel Maesen在链接的问题中评论说,最新版本的Hibernate需要最新版本的JTS。将您的依赖项从vividsolutions.jts
迁移到locationtech.jts
,并将Point
定义为org.locationtech.jts.geom.Point
更多信息:https://github.com/locationtech/jts
关于grails - 如何在Grails 4中获得反序列化的JTS Geometry字段?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57384610/