为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 Java 中将地图几何对象存储到 MS-SQL 几何列?

如何在 Java 中将地图几何对象存储到 MS-SQL 几何列?

皈依舞 2021-09-15 15:36:31
我正在尝试将几何对象存储到我的 MS-SQL 数据库中,该数据库有一个带有几何列的表。我以 JSON 格式获取几何图形。在这里,我得到了最新的 MSSQL-JDBC 版本,它具有数据类型'com.microsoft.sqlserver.jdbc.Geometry'。在 maven 中包含所需的依赖项后,此数据类型可用pom.xml。但是,当我'com.microsoft.sqlserver.jdbc.Geometry'在 java Entity 类中提到我的 MS-SQL 几何列数据类型之一并运行该应用程序时,它会引发如下错误:> Exception encountered during context initialization -  cancelling refresh attempt:  org.springframework.beans.factory.BeanCreationException:  Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]:  Invocation of init method failed; nested exception is  javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is  org.hibernate.MappingException: Could not determine type for: com.microsoft.sqlserver.jdbc.Geometry, at table: GeoTable, for columns:  [org.hibernate.mapping.Column(request_point)]下面是代码示例,Entity classimport com.microsoft.sqlserver.jdbc.Geometry;@Column(name = "request_point", columnDefinition = "Geometry")private Geometry request_point;pom.xml :     <dependency>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-data-jpa</artifactId>        <exclusions>            <exclusion>                <groupId>org.hibernate</groupId>                <artifactId>hibernate-entitymanager</artifactId>            </exclusion>            <exclusion>                <groupId>org.hibernate</groupId>                <artifactId>hibernate-core</artifactId>            </exclusion>        </exclusions>    </dependency>    <dependency>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-web</artifactId>    </dependency>    <dependency>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-jdbc</artifactId>    </dependency>我不明白为什么我的几何数据类型没有被加载,让我知道我是否遗漏了任何东西或任何其他方法来做同样的事情。任何帮助将不胜感激。
查看完整描述

2 回答

?
慕标5832272

TA贡献1966条经验 获得超4个赞

我想原因是 Hibernate 对 type 一无所知com.microsoft.sqlserver.jdbc.Geometry

我注意到您已将 hibernate-spatial 作为依赖项包含在内。Hibernate Spatial 提供与数据库无关的几何类型。查看文档


查看完整回答
反对 回复 2021-09-15
  • 2 回答
  • 0 关注
  • 174 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信