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

我正在尝试将几何对象存储到我的 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 class

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


我不明白为什么我的几何数据类型没有被加载,让我知道我是否遗漏了任何东西或任何其他方法来做同样的事情。


任何帮助将不胜感激。


皈依舞
浏览 177回答 2
2回答

慕标5832272

我想原因是 Hibernate 对 type 一无所知com.microsoft.sqlserver.jdbc.Geometry。我注意到您已将 hibernate-spatial 作为依赖项包含在内。Hibernate Spatial 提供与数据库无关的几何类型。查看文档
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java