嘿,我一直在尝试设置 Hibernate Spatial 来查询存储在 PostGreSQL 中的地理数据。尝试运行我的代码时出现以下错误。
session factory creation failed
java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.hibernate.spatial.integration.SpatialIntegrator could not be instantiated
at java.util.ServiceLoader.fail(ServiceLoader.java:224)
at java.util.ServiceLoader.access$100(ServiceLoader.java:181)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:377)
at java.util.ServiceLoader$1.next(ServiceLoader.java:445)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:339)
at org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(IntegratorServiceImpl.java:57)
at org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:247)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.<init>(StandardServiceRegistryBuilder.java:73)
at com.handyhome.service.database.HibernateUtil.buildSessionFactory(HibernateUtil.java:24)
at com.handyhome.service.database.HibernateUtil.getSessionFactory(HibernateUtil.java:39)
at com.handyhome.service.database.App.main(App.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.NoClassDefFoundError: org/hibernate/service/spi/BasicServiceInitiator
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2585)
at java.lang.Class.getConstructor0(Class.java:2885)
at java.lang.Class.newInstance(Class.java:350)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:373)
... 13 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.service.spi.BasicServiceInitiator
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 18 more
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.handyhome.service.database.HibernateUtil.buildSessionFactory(HibernateUtil.java:33)
at com.handyhome.service.database.HibernateUtil.getSessionFactory(HibernateUtil.java:39)
at com.handyhome.service.database.App.main(App.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.hibernate.spatial.integration.SpatialIntegrator could not be instantiated
at java.util.ServiceLoader.fail(ServiceLoader.java:224)
at java.util.ServiceLoader.access$100(ServiceLoader.java:181)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:377)
at java.util.ServiceLoader$1.next(ServiceLoader.java:445)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:339)
at org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(IntegratorServiceImpl.java:57)
at org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:247)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.<init>(StandardServiceRegistryBuilder.java:73)
at com.handyhome.service.database.HibernateUtil.buildSessionFactory(HibernateUtil.java:24)
... 7 more
Caused by: java.lang.NoClassDefFoundError: org/hibernate/service/spi/BasicServiceInitiator
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2585)
at java.lang.Class.getConstructor0(Class.java:2885)
at java.lang.Class.newInstance(Class.java:350)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:373)
... 13 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.service.spi.BasicServiceInitiator
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 18 more
SessionFactoryCreation 的代码
private static SessionFactory buildSessionFactory(){
try{
Configuration configuration = new Configuration().configure();
logger.log(Level.INFO,"Hibernate Configuration Loaded");
StandardServiceRegistryBuilder builder
= new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties())
;
logger.log(Level.INFO,"Service registry created");
return configuration.buildSessionFactory(builder.build());
}catch (Throwable ex){
logger.log(Level.SEVERE,"session factory creation failed",ex);
throw new ExceptionInInitializerError(ex);
}
}
如果我从我的依赖项和代码中删除休眠空间,它工作正常。但我真的需要使用 Spatial,因为我的表包含经纬度数据