- Hibernate (entity-manager, spatial...) 版本是 5.4.14
- 数据库方言如下:
org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect
- PostgresSQL 10、Postgis 2.4
因此,几何领域的定义是org.locationtech.jts.geom
关于空间方法,可以实现以下内容:覆盖、内部、缓冲区、包含...(参见具体方法)。
org.locationtech.jts.geom
不提供转换 CRS 的方法,但是 hibernate-spatial 提供(请参阅 hibernate-spatial 方言函数支持)。
transform
我们如何通过休眠空间调用 Postgis 函数?
正如PostgisPG95Dialect
该类的评论中所述:,但是没有找到使用或直接在其上方Extends the {@code PostgreSQL95Dialect} to add support for the Postgis spatial types, functions and operators
调用函数。PostgisPG95Dialect
PostgisFunctions
geometry
PostgreSQL95Dialect.transform(geometry,4326)
SpatialFunction.transform(geometry,4326)
PostgisFunctions.transform(geometry,4326)
geometry.transform(4326)
如果必须使用几何图形进行映射org.hibernate.spatial.GeolatteGeometryType
(请参阅休眠空间类型),则会出现以下错误(错误与org.hibernate.spatial.JTSGeometryType
相同):
Caused by: org.hibernate.MappingException: Could not instantiate Type: org.hibernate.spatial.GeolatteGeometryType
at org.hibernate.type.TypeFactory.type(TypeFactory.java:113)
at org.hibernate.type.TypeFactory.byClass(TypeFactory.java:70)
at org.hibernate.type.TypeResolver.heuristicType(TypeResolver.java:126)
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:473)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:455)
at org.hibernate.mapping.Property.isValid(Property.java:227)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:624)
at org.hibernate.mapping.RootClass.validate(RootClass.java:267)
at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:351)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:464)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration.buildSessionFactory(HibernateMappingContextConfiguration.java:287)
at org.grails.orm.hibernate.connections.HibernateConnectionSourceFactory.create(HibernateConnectionSourceFactory.java:86)
at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:39)
at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:23)
at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:64)
at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:52)
at org.grails.datastore.mapping.core.connections.ConnectionSourcesInitializer.create(ConnectionSourcesInitializer.groovy:24)
at org.grails.orm.hibernate.HibernateDatastore.<init>(HibernateDatastore.java:212)
at jdk.internal.reflect.GeneratedConstructorAccessor83.newInstance(Unknown Source)
atjava.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172)
... 127 common frames omitted
Caused by: java.lang.InstantiationException: org.hibernate.spatial.GeolatteGeometryType
at java.base/java.lang.Class.newInstance(Class.java:571)
at org.hibernate.type.TypeFactory.type(TypeFactory.java:105)
... 149 common frames omitted
Caused by: java.lang.NoSuchMethodException: org.hibernate.spatial.GeolatteGeometryType.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3350)
at java.base/java.lang.Class.newInstance(Class.java:556)
... 150 common frames omitted