【发布时间】:2013-10-13 01:21:13
【问题描述】:
当我尝试在 servlet 中初始化 Hibernate 4 SessionFactory 时:
Configuration config;
ServiceRegistry registry;
SessionFactory factory;
config = new Configuration();
config = config.addAnnotatedClass(Star.class); // <-- Exception here.
我得到一个例外:
SEVERE: Servlet.service() for servlet [hu.adamsan.store.TestHibernate] in context with path [/TestProject] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration;
at hu.adamsan.store.TestHibernate.doGet(TestHibernate.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at
当我在谷歌中查找时,我找不到解决方案,但是当与休眠版本不匹配时,会出现类似的错误。我做了一个类似的项目,具有完全相同的 maven 依赖项,使用相同的代码在 doGet 方法中初始化休眠,并且它有效。
maven 依赖:
mysql-connector-java 5.1.26
hibernate-core 4.2.6.Final
hibernate-validator 5.0.1.Final
commons-beanutils 1.8.3
commons-collections 3.2.1
log4j 1.2.17
slf4j-api 1.7.5
有谁知道,有什么问题吗? 有人可以提供一般性建议,如何处理和调试这些晦涩难懂的错误吗?
【问题讨论】:
标签: eclipse hibernate maven exception servlets