title: Problems using HibernateTemplate: java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
body: <p>I am quite new in Spring world and I am going crazy trying to integrate Hibernate in Spring application using <strong>HibernateTemplate</strong> abstract support class</p>
  
  <p>I have the following class to persist on database table:</p>
  
  <pre><code>package org.andrea.myexample.HibernateOnSpring.entity;
  
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="person")
  public class Person {
  
  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  private int pid;
  
  private String firstname;
  
  private String lastname;
  
  public int getPid() {
      return pid;
  }
  
  public void setPid(int pid) {
      this.pid = pid;
  }
  
  public String getFirstname() {
      return firstname;
  }
  
  public void setFirstname(String firstname) {
      this.firstname = firstname;
  }
  
  public String getLastname() {
      return lastname;
  }
  
  public void setLastname(String lastname) {
      this.lastname = lastname;
  }
  }
  </code></pre>
  
  <p>Next to it I have create an interface named <strong>PersonDAO</strong> in wich I only define my CRUD method.
  So I have implement this interface by a class named <strong>PersonDAOImpl</strong> that also extend the Spring abstract class <strong>HibernateTemplate</strong>:</p>
  
  <pre><code>package org.andrea.myexample.HibernateOnSpring.dao;
  
  import java.util.List;
  
  import org.andrea.myexample.HibernateOnSpring.entity.Person;
  import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
  
  public class PersonDAOImpl extends HibernateDaoSupport implements PersonDAO{
  
  
  public void addPerson(Person p) {
      getHibernateTemplate().saveOrUpdate(p);
  
  }
  
  public Person getById(int id) {
      // TODO Auto-generated method stub
      return null;
  }
  
  public List&lt;Person&gt; getPersonsList() {
      // TODO Auto-generated method stub
      return null;
  }
  
  public void delete(int id) {
      // TODO Auto-generated method stub
  
  }
  
  public void update(Person person) {
      // TODO Auto-generated method stub
  
  }   
  
  }
  </code></pre>
  
  <p>(at the moment I am trying to implement only the addPerson() method)</p>
  
  <p>Then I have create a main class to test the operation of insert a new object into the database table:</p>
  
  <pre><code>package org.andrea.myexample.HibernateOnSpring;
  
  import org.andrea.myexample.HibernateOnSpring.dao.PersonDAO;
  import org.andrea.myexample.HibernateOnSpring.entity.Person;
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  public class MainApp {
  
  public static void main(String[] args) {
  
      ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
      System.out.println("Contesto recuperato: " + context);
  
      Person persona1 = new Person();
  
      persona1.setFirstname("Pippo");
      persona1.setLastname("Blabla");
  
      System.out.println("Creato persona1: " + persona1);
  
      PersonDAO dao = (PersonDAO) context.getBean("personDAOImpl");
  
      System.out.println("Creato dao object: " + dao);
  
      dao.addPerson(persona1);
  
      System.out.println("persona1 salvata nel database");
  }
  
  }
  </code></pre>
  
  <p>As you can see the <strong>PersonDAOImpl</strong> class <strong>extends HibernateTemplate</strong> so I think that it have to contain the operation of setting of the sessionFactory...</p>
  
  <p>The problem is that when I try to run this MainApp class I obtain the following exception:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
      at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:323)
      at org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:235)
      at org.springframework.orm.hibernate3.HibernateTemplate.getSession(HibernateTemplate.java:457)
      at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:392)
      at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
      at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:737)
      at org.andrea.myexample.HibernateOnSpring.dao.PersonDAOImpl.addPerson(PersonDAOImpl.java:12)
      at org.andrea.myexample.HibernateOnSpring.MainApp.main(MainApp.java:26)
  </code></pre>
  
  <p>Why I have this problem? how can I solve it?</p>
  
  <p>To be complete I also insert my <strong>pom.xml</strong> containing my dependencies list:</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;groupId&gt;org.andrea.myexample&lt;/groupId&gt;
  &lt;artifactId&gt;HibernateOnSpring&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;jar&lt;/packaging&gt;
  
  &lt;name&gt;HibernateOnSpring&lt;/name&gt;
  &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
  &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  &lt;/properties&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;version&gt;3.8.1&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Dipendenze di Spring Framework --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
          &lt;version&gt;3.2.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
          &lt;version&gt;3.2.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
          &lt;version&gt;3.2.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-context-support&lt;/artifactId&gt;
          &lt;version&gt;3.2.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
  
      &lt;dependency&gt;   &lt;!-- Usata da Hibernate 4 per LocalSessionFactoryBean --&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
          &lt;version&gt;3.2.0.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Dipendenze per AOP --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;cglib&lt;/groupId&gt;
          &lt;artifactId&gt;cglib&lt;/artifactId&gt;
          &lt;version&gt;2.2.2&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Dipendenze per Persistence Managment --&gt;
  
      &lt;dependency&gt;    &lt;!-- Apache BasicDataSource --&gt;
          &lt;groupId&gt;commons-dbcp&lt;/groupId&gt;
          &lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt;
          &lt;version&gt;1.4&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;    &lt;!-- MySQL database driver --&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;5.1.23&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;    &lt;!-- Hibernate --&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;4.1.9.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
  
  
  &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>