I want to use hibernate spatial with mysql and spring boot. I tried but failing. application.properties file given below
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;
}
But I am getting Exception when deploy
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')
}
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.spatial.dialect.mysql.MySQLSpatial5InnoDBDialect] as strategy [org.hibernate.dialect.Dialect] at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:113) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
Is there any version related problem????
If we match your exception at runtime :
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.spatial.dialect.mysql.MySQLSpatial5InnoDBDialect] as strategy [org.hibernate.dialect.Dialect] at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:113) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
with the source code of 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() + "]"
);
}
}
We understand that org.hibernate.spatial.dialect.mysql.MySQLSpatial5InnoDBDialect
class is not loadable by the classloader. It is probably not in the classpath.
I suppose you should add the hibernate spatial dependency that matches with your Hibernate version.