【发布时间】:2017-05-30 12:10:15
【问题描述】:
背景: 在最终迁移到 PostgreSQL 之前,我一直在尝试让几何数据类型与 H2 一起工作。我的代码可以编译,但是当我尝试检索用户模型时,由于几何位置而失败。我得到的列“LOCATION BINARY(255): 'X'aced005....”的值太长了
application.properties
spring.datasource.url=jdbc:h2:file:./members.db
server.port = 8090
gradle.build,主要的依赖是vividsolutions和一些hibernate的。
buildscript {
ext {
springBootVersion = '1.5.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile('org.springframework.boot:spring-boot-starter-test')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web')
compile (group: 'com.vividsolutions', name: 'jts', version: '1.13')
compile (group: 'org.orbisgis', name: 'h2gis', version: '1.3.1')
compile (group: 'org.hibernate', name: 'hibernate-core', version: '5.2.10.Final')
compile (group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.2.10.Final')
compile (group: 'org.hibernate', name: 'hibernate-spatial', version: '5.2.10.Final')
runtime('com.h2database:h2')
// runtime('org.postgresql:postgresql')
}
实体:如果我不为应用程序运行的位置提供 getter/setter,但那是因为它实际上并没有尝试访问该数据。我尝试使用其他注释来定义几何位置,@Type(type="org.hibernate.spatial.GeometryType") Hibernate spatial docs。该注释甚至无法编译,因为尽管在 gradle 中有依赖项,但它无法识别 hibernate.spatial。
package com.alex_donley.event_mapper.Entities;
import com.vividsolutions.jts.geom.Geometry;
import javax.persistence.*;
/**
* Created by Indycorps on 5/11/2017.
*/
@Entity
public class User {
@Id
@GeneratedValue
private long id;
private String firstName;
private String lastName;
@Column(columnDefinition="Geometry")
private Geometry location;
public User(String firstName, String lastName, Geometry location) {
this.firstName = firstName;
this.lastName = lastName;
this.location = location;
}
public User(){}
public long getId() {
return id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
//Create getters and setters for location to actually output stuff
public Geometry getLocation() {
return location;
}
public void setLocation(Geometry location) {
this.location = location;
}
}
【问题讨论】:
标签: spring hibernate jpa jackson postgis