【发布时间】:2019-02-17 04:12:27
【问题描述】:
我正在尝试将几何对象存储到我的 MS-SQL 数据库中,该数据库有一个带有几何列的表。我得到 JSON 格式的几何图形。
Here 我得到了最新的 MSSQL-JDBC 版本,它的数据类型为 'com.microsoft.sqlserver.jdbc.Geometry'。
在 maven pom.xml 中包含所需的依赖项后,此数据类型可用。
但是当我在 java Entity 类中提到我的 MS-SQL 几何列数据类型之一为 'com.microsoft.sqlserver.jdbc.Geometry' 并运行应用程序时,它会引发如下错误:
> 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>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.0.0.jre10</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.10.Final</version>
</dependency>
我在 application.properties 中的以下几行
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
示例几何字符串 -
{\"spatialReference\": {\"latestWkid\": 3434,\"wkid\": 4353}, \"x\": -10538019.079024673,\"y\": 4720603.9173474545}
我不明白为什么我的几何数据类型没有被加载,如果我缺少任何东西或任何其他方法来做同样的事情,请告诉我。
任何帮助将不胜感激。
【问题讨论】:
标签: java spring-boot mssql-jdbc hibernate-spatial