Java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session 更新到休眠 4 后

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30801597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 17:41:11  来源:igfitidea点击:

Java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session after update to hibernate 4

javaspringhibernate

提问by Patrick van Deudekom

After updating to hibernate 4 and changing some needed settings I get the following error:

更新到休眠 4 并更改一些需要的设置后,我收到以下错误:

SEVERE: Servlet.service() for servlet [default] in context with path [/ESBCollector] threw exception [Filter execution threw an exception] with root cause
java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
    at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:328)
    at org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:208)
    at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.getSession(OpenSessionInViewFilter.java:294)
    at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:208)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

It looks like hibernate3 is still being used to open the session. Any ideas on which i forgot to do?

看起来 hibernate3 仍在用于打开会话。我忘记做的任何想法?

采纳答案by Patrick van Deudekom

Had to change the openSessionInViewFilter in web.xml

必须更改 web.xml 中的 openSessionInViewFilter

回答by Vlad Mihalcea

You need to run mvn dependency:treeand search for Hibernate 3 jars in your output. When you find the dependencies adding Hibernate 3 to your dependency tree, you need to simply exclude them, like so:

您需要mvn dependency:tree在输出中运行并搜索 Hibernate 3 jars。当您发现将 Hibernate 3 添加到您的依赖树的依赖项时,您需要简单地排除它们,如下所示:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>${spring.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>

回答by M. Deinum

You are using hibernate4 however your web.xmlstill used the [OpenSessionInViewFilter] for hibernate3 instead of the [OpenSessionInViewFilter] for hibernate4.

您正在使用 hibernate4,但是您web.xml仍然使用 [ OpenSessionInViewFilter] 来表示 hibernate3 而不是 [ OpenSessionInViewFilter] 来表示 hibernate4。

To fix find the filter in the web.xml.

要修复在web.xml.

<filter>
    <filter-name>osiv-filter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>

And replace the 3 with a 4.

并将 3 替换为 4。

<filter>
    <filter-name>osiv-filter</filter-name>
    <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>

回答by Николай Соха

There is a possibility that you have imported old (hibernate3) classes within code, like

您有可能在代码中导入了旧的 (hibernate3) 类,例如

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
// needs to be replaced to 
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;