本文介绍了如何在Grails 4中获得反序列化的JTS Geometry字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PostgreSQL + PostGIS + Grails 4 + Geoserver + React + JTS构建小型Geo服务器.域类具有一个com.vividsolutions.jts.geom.Point字段,该字段映射到sqlType: 'geometry(Point,4326)'.当我搜索任何findBy...(...)搜索时,我无法获得结果,因为它不可能deserialize

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

在Grails 2.x中,我没有遇到这个问题.这是我三年来第一次在Grails中编程.

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
  }
}

这是错误消息:

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.

推荐答案

根据文档 Grails 4与最新版本的Hibernate 5.4兼容.
Karel Maesen在链接的问题中评论说,最新版本的Hibernate需要最新版本的JTS.
将您的依赖项从vividsolutions.jts迁移到locationtech.jts,并将Point定义为org.locationtech.jts.geom.Point更多信息: https://github.com/locationtech/jts

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

这篇关于如何在Grails 4中获得反序列化的JTS Geometry字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 15:58