Hibernate-пространственный jpa с myql и Spring boot 1.5.7 не работает

Я хочу использовать спящий пространственный с MySQL и весенней загрузки. Я пытался, но безуспешно. файл application.properties, указанный ниже

spring.datasource.url=jdbc:mysql://localhost:3306/tour_management
spring.datasource.username=root
spring.datasource.password=admin
endpoints.actuator.enabled=true
endpoints.info.enabled=true

spring.jpa.properties.hibernate.dialect = 
org.hibernate.spatial.dialect.mysql.MySQLSpatial5InnoDBDialect
spring.jpa.database-platform = 
org.hibernate.spatial.dialect.mysql.MySQLSpatial5InnoDBDialect



@Data
@Entity(name = "Place")
public class PlaceEntity extends BaseEntity {
@Id
@GeneratedValue
@Column(name = "ID")
private long id;
@Column(name = "NAME")
private String name;
@Column(name = "CODE")
private String code;
@Column(name = "LONGITUDE")
private Double longitude;
@Column(name = "LATITUDE")
private Double latitude;

@Column(name = "LOCATION",columnDefinition = "geometry(Point,4326)")
private Point location;
}

Но я получаю исключение при развертывании

buildscript {
ext {
    springBootVersion = '1.5.7.RELEASE'
}
repositories {
    mavenCentral()
    maven {
        url "http://www.hibernatespatial.org/repository"
    }
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-
plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
group = 'com.fm'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven {
    url "http://www.hibernatespatial.org/repository"
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('mysql:mysql-connector-java')
compile('org.projectlombok:lombok:1.14.8')
compile('org.springframework.boot:spring-boot-starter-web')
compile('com.vividsolutions:jts:1.13')
testCompile('org.springframework.boot:spring-boot-starter-test')
}

Причина: org.hibernate.boot.registry.selector.spi.StrategySelectionException: невозможно разрешить имя [org.hibernate.spatial.dialect.mysql.MySQLSpatial5InnoDBDialect] в качестве стратегии [org.hibernate.dialect.Dialect] в org.hiber.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:113) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

Есть ли проблема, связанная с версией????

1 ответ

Решение

Если мы сопоставим ваше исключение во время выполнения:

Причина: org.hibernate.boot.registry.selector.spi.StrategySelectionException: невозможно разрешить имя [org.hibernate.spatial.dialect.mysql.MySQLSpatial5InnoDBDialect] в качестве стратегии [org.hibernate.dialect.Dialect] в org.hiber.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:113) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

с исходным кодом StrategySelectorImpl:

@Override
    @SuppressWarnings("unchecked")
    public <T> Class<? extends T> selectStrategyImplementor(Class<T> strategy, String name) {
        final Map<String,Class> namedStrategyImplementorMap = namedStrategyImplementorByStrategyMap.get( strategy );
        if ( namedStrategyImplementorMap != null ) {
            final Class registered = namedStrategyImplementorMap.get( name );
            if ( registered != null ) {
                return (Class<T>) registered;
            }
        }

        try {
            return classLoaderService.classForName( name );
        }
        catch (ClassLoadingException e) {
            throw new StrategySelectionException(
                    "Unable to resolve name [" + name + "] as strategy [" + strategy.getName() + "]"
            );
        }
    }

Мы понимаем что org.hibernate.spatial.dialect.mysql.MySQLSpatial5InnoDBDialect класс не загружается загрузчиком классов. Это, вероятно, не в пути к классам.

Я полагаю, вы должны добавить пространственную зависимость спящего режима, которая соответствует вашей версии Hibernate.

Другие вопросы по тегам