我無法在創建模式下使用 hibernate-spatial 啟動我的 spring boot(2.6.3) 專案。它告訴我型別“幾何不存在”。幾何型別來自休眠空間庫。
但是,我應用了所有必要的東西:
添加休眠空間依賴(我的版本 5.6.3.Final)
使用 org.hibernate.spatial.dialect.postgis.PostgisDialect 方言 而且這個類已被棄用,并且檔案對應相同的版本,它仍然指示使用它,我什么都不懂(https://docs.jboss.org /hibernate/orm/5.6/userguide /html_single/Hibernate_User_Guide.html#spatial)
使用 geolatte 組或 jts 組中的幾何型別盡管我有一個錯誤,它無法創建表,因為型別“幾何不存在”。
這是我的 Maven 依賴項:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>5.6.3.Final</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.1</version>
</dependency>
<!--<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
<version>1.18.2</version>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
我的屬性:
spring:
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/postgres?currentSchema=hibernatespatial
username: postgres
password:
jpa:
hibernate:
ddl-auto: create
show-sql: true
properties:
hibernate:
dialect: org.hibernate.spatial.dialect.postgis.PostgisDialect
open-in-view: false
database-platform: org.hibernate.spatial.dialect.postgis.PostgisDialect
我的物體類:
package org.test.hibernate.spatial;
import org.geolatte.geom.Geometry;
import javax.persistence.*;
@Entity
@Table
public class Person {
@Id
@GeneratedValue
private Long id;
private String name;
private String lastname;
private String age;
private Geometry geom;
public Geometry getGeom() {
return geom;
}
public void setGeom(Geometry geom) {
this.geom = geom;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
我的存盤庫類:
package org.test.hibernate.spatial;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PersonRepository extends JpaRepository<Person, Long> {
}
我的引導類:
package org.test.hibernate.spatial;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@EnableJpaRepositories
@EnableTransactionManagement
public class TestHibernateSpatialApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(TestHibernateSpatialApplication.class, args);
}
public void run(String... args) throws Exception {
}
}
我的 postgreSQL 資料庫是 14 版本。有人知道出了什么問題嗎?
uj5u.com熱心網友回復:
PostGIS 是 Postgres 擴展,需要為每個資料庫啟用:
安裝 PostGIS 后,需要在要使用它的每個資料庫中啟用(第 3.3 節,“創建空間資料庫”)或升級(第 3.4 節,“升級空間資料庫”)。
[...]
運行在要在空間上啟用的資料庫中的以下 SQL 片段:
CREATE EXTENSION IF NOT EXISTS plpgsql;
CREATE EXTENSION postgis;
另請注意,擴展默認安裝到默認架構(例如public)。因此,在使用該currentSchema選項時,請務必不要意外排除安裝了 postgis 的模式。為了防止這種情況,可以將 postgis 模式添加到currentSchema(例如jdbc:postgresql://localhost:5432/tst?currentSchema=app1,public),或者將 postgis 移動到首選模式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/424551.html
上一篇:給我最高價值的JPQL查詢
