Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session

Tags:

i am trying to integrate my already working spring project with hibernate, but this is the error i am getting on start up.

EVERE: Servlet.service() for servlet [appServlet] in context with path [/TelephoneDirectory] threw exception [Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;] with root cause java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;     at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:322)     at org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:233)     at org.springframework.orm.hibernate3.HibernateTemplate.getSession(HibernateTemplate.java:457)     at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:393)     at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)     at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912)     at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:904)     at com.emumba.telephonedirectory.repository.JdbcPersonDao.getPersonsList(JdbcPersonDao.java:36)     at com.emumba.telephonedirectory.service.SimpleDirectoryManager.getAllPersons(SimpleDirectoryManager.java:23)     at com.emumba.telephonedirectory.web.HomeController.home(HomeController.java:42)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)     at java.lang.reflect.Method.invoke(Unknown Source)     at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)     at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)     at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)     at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)     at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)     at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)     at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)     at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)     at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)     at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)     at java.lang.Thread.run(Unknown Source) 

I have googled it but all i could find was that similar problems were caused by duplicates in classpath but i have looked very closely and i dont think their are any duplicates in my classpath. (may be i am wrong.) Heres a screen shot of jars in my classpathenter image description here

i am stuck, any help will be greatly appreciated

EDIT: Search for org.hibernate.SessionFactory gives

enter image description here

like image 809
Khizar Avatar asked Jan 10 '12 05:01

Khizar


1 Answers

The problem is that you have hibernate-core-4.0.0.Final.jar in your classpath, but Spring 3.1 uses hibernate-core-3.6.0.Final.jar (see here Spring 3.1 artifact and dependencies).

Remove Hibernate 4.0 and put Hibernate 3.6 instead in your classpath.

BTW, there might some more such miss matches. It's better to use maven to take care of dependencies.

EDIT - some more details

In Hibernate 3.6 the interface Session was in package org.hibernate.classic whereas in Hibernate 4.0 it was moved to the package org.hibernate.

In Hibernate 3.6 the SessionFactory.openSession no longer returns an org.hibernate.classic.Session, rather it returns an org.hibernate.Session. This is a refactor that breaks client code...

like image 74
yair Avatar answered Sep 29 '22 13:09

yair