2017-09-17 103 views
0

我想在我的Java Spring Spring Web應用程序中使用MySQL實現空間。當我改變SessionFactory Bean和MySQL5SpatialDialect

properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5SpatialDialect"); 

我得到關於SessionFactory的以下錯誤

properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect"); 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 
2017-09-18 01:27:34.796 ERROR 10371 --- [ restartedMain] o.s.boot.SpringApplication    : Application startup failed 

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'courseController': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [eu/barz/familykurse/config/SpringMvcConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] 
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] 
    at eu.barz.familykurse.BabyKurseApplication.main(BabyKurseApplication.java:14) [classes/:na] 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131] 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131] 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131] 
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131] 
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.5.6.RELEASE.jar:1.5.6.RELEASE] 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [eu/barz/familykurse/config/SpringMvcConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    ... 24 common frames omitted 
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:271) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:511) ~[spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:495) ~[spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    ... 34 common frames omitted 
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.dialect.MySQL5SpatialDialect] as strategy [org.hibernate.dialect.Dialect] 
    at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:126) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:194) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:152) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:139) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:133) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:74) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:51) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    ... 51 common frames omitted 


Process finished with exit code 0 

CourseController.java

package eu.barz.familykurse.controller; 

import java.io.IOException; 
import java.security.Principal; 
import java.sql.Blob; 
import eu.barz.familykurse.services.GeoLocationService; 
import org.hibernate.Hibernate; 
import eu.barz.familykurse.domain.Course; 
import eu.barz.familykurse.domain.User; 
import eu.barz.familykurse.services.CourseService; 
import eu.barz.familykurse.services.UserService; 
import org.hibernate.Session; 
import org.hibernate.SessionFactory; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.ui.Model; 
import org.springframework.web.bind.annotation.*; 
import org.springframework.web.multipart.MultipartFile; 

@Controller 
public class CourseController { 

    private CourseService courseService; 
    private UserService userService; 
    private GeoLocationService geoLocationService; 

    @Autowired 
    public void setCourseService(CourseService courseService){ 
     this.courseService = courseService; 
    } 

    @Autowired 
    public void setUserService(UserService userService){ 
     this.userService = userService; 
    } 

    @Autowired 
    public void setGeoLocationService(GeoLocationService geoLocationService) { this.geoLocationService = geoLocationService; } 

    @Autowired 
    SessionFactory sessionFactory; 

    @RequestMapping("/course") 
    public String returnCourse(){ 
     return "redirect:/index"; 
    } 

    @GetMapping("/user/course-admin") 
    public String returnCourse(Model model, Principal principal){ 
     model.addAttribute("course", new Course()); 
     model.addAttribute("courses", courseService.listCourses(principal.getName())); 
     return "user/course-admin"; 
    } 

    @PostMapping("/user/course-admin") 
    public String returnCourseSubmit(Model model, Principal principal, @ModelAttribute Course course, @RequestParam("file") MultipartFile file){ 
     System.out.println("POSTed"); 


     User currentUser = userService.getUser(principal.getName()); 
     course.setUser(currentUser); 
     Session session = sessionFactory.openSession(); 

     if(course.getId() == null){ 
      try { 
       Blob image = Hibernate.getLobCreator(session).createBlob(file.getBytes()); 
       course.setBanner(image); 
      } catch(IOException e){ 
       e.printStackTrace(); 
      } 




      //TODO 
      //https://maps.googleapis.com/maps/api/geocode/json?address=Sophie-Lützen-Weg+6+24106+Kiel&key=AIzaSyANbuHa59iS569gA6KHfnfU21T1wd9VdvU 
      courseService.saveCourse(course); 
     } else { 
      Blob banner = courseService.getCourse(course.getId()).getBanner(); 
      course.setBanner(banner); 
      //TODO getLocation 
      //https://maps.googleapis.com/maps/api/geocode/json?address=Sophie-Lützen-Weg+6+24106+Kiel&key=AIzaSyANbuHa59iS569gA6KHfnfU21T1wd9VdvU 
      courseService.updateCourse(course); 
     } 
     model.addAttribute("courses", courseService.listCourses(principal.getName())); 

     return "/user/course-admin"; 
    } 

    @PostMapping("/user/course-admin/course-form") 
    public String returnCourseEditForm(@RequestParam(value = "courseId") int courseId, Model model){ 
     System.out.println("POSTed"); 
     System.out.println(courseId); 
     Course course = courseService.getCourse(courseId); 
     model.addAttribute("course", course); 

     //User currentUser = userService.getUser(2); 


     return "user/course-admin/course-form"; 
    } 

    @RequestMapping("/course/{name}") 
    public String returnCourseById(@PathVariable String name, Model model){ 
     String[] seperatedString = name.split("-"); 

     Integer id = Integer.parseInt(seperatedString[seperatedString.length-1]) ; 
     model.addAttribute("course", courseService.getCourse(id)); 

     return "course"; 
    } 
} 
目前我使用下面的方言

我SpringMVCConfiguration.java,我已經定義了一個SessionFactory

package eu.barz.familykurse.config; 



import org.hibernate.SessionFactory; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; 
import org.springframework.jdbc.datasource.DriverManagerDataSource; 
import org.springframework.orm.hibernate5.HibernateTransactionManager; 
import org.springframework.orm.hibernate5.LocalSessionFactoryBean; 
import org.springframework.web.servlet.LocaleResolver; 
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; 
import org.springframework.web.servlet.i18n.SessionLocaleResolver; 
import javax.sql.DataSource; 
import java.util.Locale; 
import java.util.Properties; 


@Configuration 


public class SpringMvcConfiguration extends WebMvcConfigurerAdapter{ 
    @Bean 
    public LocaleResolver localeResolver(){ 
     SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver(); 
     sessionLocaleResolver.setDefaultLocale(Locale.GERMAN); 
     return sessionLocaleResolver; 
    } 

    @Bean 
    LocaleChangeInterceptor localeChangeInterceptor(){ 
     LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); 
     localeChangeInterceptor.setParamName("lang"); 
     return localeChangeInterceptor; 
    } 

    @Override 
    public void addInterceptors(InterceptorRegistry interceptorRegistry){ 
     interceptorRegistry.addInterceptor(localeChangeInterceptor()); 
    } 



    @Bean 
    public LocalSessionFactoryBean sessionFactory() { 
     LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); 
     sessionFactory.setDataSource(dataSource()); 
     sessionFactory.setPackagesToScan("eu.barz.familykurse.domain"); 
     sessionFactory.setHibernateProperties(hibernateProperties()); 

     return sessionFactory; 
    } 

    @Bean 
    public DataSource dataSource() { 
     DriverManagerDataSource dataSource = new DriverManagerDataSource(); 
     dataSource.setDriverClassName("com.mysql.jdbc.Driver"); 
     dataSource.setUrl("jdbc:mysql://localhost:3306/family_kurse?useSSL=false"); 
     dataSource.setUsername("XXX"); 
     dataSource.setPassword("YYY"); 

     return dataSource; 
    } 

    @Bean 
    @Autowired 
    public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) { 

     HibernateTransactionManager txManager = new HibernateTransactionManager(); 
     txManager.setSessionFactory(sessionFactory); 

     return txManager; 
    } 

    @Bean 
    public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { 
     return new PersistenceExceptionTranslationPostProcessor(); 
    } 

    Properties hibernateProperties() { 
     Properties properties = new Properties(); 
     properties.setProperty("hibernate.ddl-auto", "update"); 
     properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5SpatialDialect"); 
     properties.setProperty("hibernate.show_sql", "true"); 
     return properties; 
    } 

} 

最後我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>eu.barz</groupId> 
    <artifactId>baby-kurse</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>baby-kurse</name> 
    <description>Webseite für Babykurse</description> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.6.RELEASE</version> 
     <relativePath/> <!-- lookup parent from repository --> 
    </parent> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
     <java.version>1.8</java.version> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-thymeleaf</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-devtools</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-pool</groupId> 
      <artifactId>commons-pool</artifactId> 
      <version>1.4</version> 
      <!-- <version>1.5.6</version> --> 
     </dependency> 


     <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core --> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-core</artifactId> 
      <version>5.2.11.Final</version> 
     </dependency> 

     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-search-orm</artifactId> 
      <version>5.8.0.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <version>5.1.43</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-web</artifactId> 
      <version>4.2.3.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-config</artifactId> 
      <version>4.2.3.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.thymeleaf.extras</groupId> 
      <artifactId>thymeleaf-extras-springsecurity4</artifactId> 
      <version>2.1.2.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-core</artifactId> 
      <version>4.3.10.RELEASE</version> 
     </dependency> 
     <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-spatial --> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-spatial</artifactId> 
      <version>5.2.11.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-jpa</artifactId> 
     </dependency> 

    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 


</project> 

我真的不能確定爲什麼在這種錯誤改變方言結果。如果有人會指出我正確的方向,我會非常感激。

乾杯MAIK

回答

1

按照spatial documentationsource code

正確的包是org.hibernate.spatial.dialect.mysql.MySQL5SpatialDialect而不是org.hibernate.dialect.MySQL5SpatialDialect

所以我覺得這個應該工作:

properties.setProperty("hibernate.dialect", "org.hibernate.spatial.dialect.mysql.MySQL5SpatialDialect"); 
相關問題