我正在尝试在程序中引入缓存,但我在运行时遇到异常
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/boot/spi/SessionFactoryOptions
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetPublicMethods(Class.java:2902)
at java.lang.Class.getMethods(Class.java:1615)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.applyInjections(AbstractServiceRegistryImpl.java:278)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:269)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:231)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:295)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2444)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2440)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)
at com.hibernate.exercise6.utilities.HibernateUtil.<clinit>(HibernateUtil.java:41)
at com.hibernate.exercise6.dao.PersonDAO.<init>(PersonDAO.java:37)
at com.hibernate.exercise6.service.EmployeeService.<init>(EmployeeService.java:40)
at com.hibernate.exercise6.app.GUIMain.<clinit>(GUIMain.java:46)
Caused by: java.lang.ClassNotFoundException: org.hibernate.boot.spi.SessionFactoryOptions
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 16 more
下面是我的HibernateUtil类
HibernateUtil.java
public class HibernateUtil{
private static SessionFactory sessionFactory;
private static AnnotationConfiguration cfg;
private static ServiceRegistry serviceRegistry;
static{
cfg = new AnnotationConfiguration()
.configure()
.addAnnotatedClass(com.hibernate.exercise6.model.Employee.class)
.addAnnotatedClass(com.hibernate.exercise6.model.Name.class)
.addAnnotatedClass(com.hibernate.exercise6.model.Address.class)
.addAnnotatedClass(com.hibernate.exercise6.model.OtherInfo.class)
.addAnnotatedClass(com.hibernate.exercise6.model.Contact.class)
.addAnnotatedClass(com.hibernate.exercise6.model.Role.class)
.setProperty("hibernate.enable_lazy_load_no_trans","true")
.setProperty("hibernate.cache.provider_class","org.hibernate.cache.EhCacheProvider")
.setProperty("hibernate.cache.region.factory_class","org.hibernate.cache.ehcache.EhCacheRegionFactory")
.setProperty("hibernate.cache.use_second_level_cache","true")
.setProperty("hibernate.cache.use_query_cache","true");
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();
sessionFactory = cfg.buildSessionFactory(serviceRegistry);
}
public static SessionFactory getSessionFactory(){
return sessionFactory;
}
}
我正在使用org-hibernate-core-4.3.10-Final.jar
我找不到这条路org/hibernate/boot/spi/SessionFactoryOptions
有什么建议可以解决这个问题吗?
答案 0 :(得分:3)
听起来你的类路径上有不同的hibernate版本。