title: java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration
body: <p>I am trying to create an web application of my own using Spring MVC.But after configuring everything i am getting the following error</p>
  
  <h2>Error :</h2>
  
  <pre><code>WARNING: Exception encountered during context initialization - cancelling refresh attempt
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/Iroom-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration;
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:736)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
  at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663)
  at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:629)
  at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:677)
  at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:548)
  at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489)
  at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
  at javax.servlet.GenericServlet.init(GenericServlet.java:158)
  at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1269)
  at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1182)
  at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1072)
  at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5368)
  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5660)
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
  at java.util.concurrent.FutureTask.run(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)
  Caused by: java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration;
  at org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean.postProcessMappings(AnnotationSessionFactoryBean.java:155)
  at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:657)
  at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:189)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
  ... 28 more
  </code></pre>
  
  <p>I have tried changing the jar versions thinking that it is some kind of jars incompatibility issue.But there are a lot of jars and i am a newbie to spring.I have given below my code and the jars i am using.</p>
  
  <h2>web.xml</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
    &lt;display-name&gt;Iroom3&lt;/display-name&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;Iroom&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Iroom&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <h2>Iroom-servlet.xml</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/beans     
  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/context 
  http://www.springframework.org/schema/context/spring-context-3.0.xsd
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
  http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"&gt;
  
  &lt;context:component-scan base-package="org.iroom.controller"/&gt;
  &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix" value="/WEB-INF/jsp/"/&gt;
      &lt;property name="suffix" value=".jsp"/&gt;  
  &lt;/bean&gt;
  
  &lt;!-- Defining data sources --&gt;
  &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
      &lt;property name="url" value="jdbc:mysql://localhost:3306/iroom"/&gt;
      &lt;property name="username" value="root"/&gt;
      &lt;property name="password" value="root"/&gt;
  &lt;/bean&gt;
  
  &lt;!-- Defining Hibernate Session factory bean defenition --&gt;
  &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
      &lt;property name="annotatedClasses"&gt;
          &lt;list&gt;
              &lt;value&gt;org.iroom.entity.Roommates&lt;/value&gt;           
          &lt;/list&gt;
      &lt;/property&gt;
  
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
          &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
          &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;              
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="RoommatesDAO" class="com.journaldev.spring.dao.PersonDAOImpl"&gt;
      &lt;property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" /&gt;
  &lt;/bean&gt;
  
  
  &lt;bean id="roommatesService" class="org.iroom.dao.impl.RoommatesDAOImpl"&gt;
      &lt;property name="RoommatesDAO" ref="RoommatesDAO"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" /&gt;
  &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <h2>Jar Files Used</h2>
  
  <p><a href="https://i.stack.imgur.com/mfcZw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mfcZw.png" alt="enter image description here"></a></p>
  
  <p>can anyone help me out figuring out where i am missing something.I have been working on this for around half a day and still couldnt figure out where i am making mistake.Kindly help me out on this</p>