title: Error creating bean with name 'sessionFactory' defined in ServletContext
body: <p>I know this is a duplicate, but I've spent days working with all the solutions. I havent been able to get any to work. Can someone please take a look.</p>
  
  <p>If any additional information is required, please let me know.</p>
  
  <p>My Stacktrace is as follows:</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Unable to load class [ com.davis.ty.domain.Products] declared in Hibernate configuration &lt;mapping/&gt; entry
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
  </code></pre>
  
  <p>My servlet.xml is as follow:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:p="http://www.springframework.org/schema/p"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"&gt;
  
  
      &lt;!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --&gt;
      &lt;context:annotation-config /&gt;
      &lt;context:component-scan base-package="com.davis.ty" /&gt;
  
      &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --&gt;
      &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
  
      &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --&gt;
      &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix" value="/WEB-INF/views/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
          p:location="/WEB-INF/jdbc.properties" /&gt;
  
      &lt;bean id="messageSource"
          class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
          &lt;property name="basename" value="classpath:messages" /&gt;
          &lt;property name="defaultEncoding" value="UTF-8" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="dataSource"
          class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close"
          p:driverClassName="${jdbc.driverClassName}"
          p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
          p:password="${jdbc.password}" /&gt;
  
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="configLocation"&gt;
              &lt;value&gt;classpath:hibernate.cfg.xml&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;${jdbc.dialect}&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
  
      &lt;/bean&gt;
  
      &lt;tx:annotation-driven /&gt;
      &lt;bean id="transactionManager"
          class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>My hibrenate.cfg.xml is this :</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;mapping class="com.davis.ty.domain.Products" /&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>My sessionfactory code is:</p>
  
  <pre><code>package com.davis.ty.dao;
  
  import java.util.List;
  
  import org.hibernate.SessionFactory;
  import org.springframework.stereotype.Repository;
  import org.springframework.beans.factory.annotation.Autowired;
  
  import com.davis.ty.domain.Products;
  
  @Repository
  public class ProductsDAOImpl implements  ProductsDAO{
  
      @Autowired
      private SessionFactory sessionFactory;
  
      public void addProduct(Products products) {
          sessionFactory.getCurrentSession().save(products);
      }
  
      public void updateProduct(Products products)
       {
            sessionFactory.getCurrentSession().merge(products);
       }
  
      @SuppressWarnings("unchecked")
      public List&lt;Products&gt; listProducts() {
  
          return sessionFactory.getCurrentSession().createQuery("from Products").list();
      }
  
      public void removeProducts(int id) {
          Products products = (Products) sessionFactory.getCurrentSession().load(
                  Products.class, id);
          if (null != products) {
              sessionFactory.getCurrentSession().delete(products);
          }
  
      }
  
      @Override
      public Products getProductsById(int id) {
  
           return (Products) sessionFactory.getCurrentSession().get(Products.class, id);
  
      }
  
  }
  </code></pre>
  
  <p>My form class is as follows:</p>
  
  <pre><code>package com.davis.ty.domain;
  
  
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.GenerationType;
      import javax.persistence.Id;
      import javax.persistence.Table;
      import java.math.BigDecimal;
  
      /**
       * Entity bean with JPA annotations
       * Hibernate provides JPA implementation
       * @author pankaj
       *
       */
      @Entity
      @Table(name="products")
      public class Products {
  
          @Id
          @Column(name="ID")
          @GeneratedValue(strategy=GenerationType.IDENTITY)
          private int id;
  
          @Column(name="CODE")
          private int code;
  
          @Column(name="Dept")
          private int dept;
  
          @Column(name="DESC")
          private String desc;
  
          @Column(name="Price")
          private BigDecimal price;
  
          @Column(name="Tax")
          private BigDecimal tax;
  
          @Column(name="Shipping")
          private BigDecimal ship;
  
          public int getId() {
              return id;
          }
  
          public void setId(int id) {
              this.id = id;
          }
  
          public int getCode() {
              return code;
          }
  
          public void setCode(int code) {
              this.code = code;
          }
  
          public int getDept() {
              return dept;
          }
  
          public void setDept(int dept) {
              this.dept = dept;
          }
  
          public String getDesc() {
              return desc;
          }
  
          public void setDesc(String desc) {
              this.desc = desc;
          }
  
          public BigDecimal getPrice() {
              return price;
          }
  
          public void setPrice(BigDecimal price) {
              this.price = price;
          }
  
          public BigDecimal getTax() {
              return tax;
          }
  
          public void setTax(BigDecimal tax) {
              this.tax = tax;
          }
  
          public BigDecimal getShip() {
              return ship;
          }
  
          public void setShip(BigDecimal ship) {
              this.ship = ship;
          }
  
  
      }
  </code></pre>