title: An AnnotationConfiguration instance is required
body: <p>I am new in spring and hibernate. Now I am trying to save some data to mySql database. But I am getting some error. Are there any configuration needed in dispatcher-servelet.xml for using hibernate annotation. How can I solve the problem?</p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.ExceptionInInitializerError
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:839)
  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
  org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
  
  
  root cause 
  java.lang.ExceptionInInitializerError
  com.application.util.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:21)
  com.application.service.EmployeeServiceImpl.add(EmployeeServiceImpl.java:22)
  com.application.controller.UserController.onSubmit(UserController.java:34)
  org.springframework.web.servlet.mvc.SimpleFormController.onSubmit(SimpleFormController.java:415)
  org.springframework.web.servlet.mvc.SimpleFormController.onSubmit(SimpleFormController.java:387)
  org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:272)
  org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:268)
  org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
  org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
  org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
  
  
  root cause 
  org.hibernate.MappingException: An AnnotationConfiguration instance is required to use &lt;mapping class="com.application.domain.Employee"/&gt;
  org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1600)
  org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
  org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
  org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
  org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
  org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
  com.application.util.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:18)
  com.application.service.EmployeeServiceImpl.add(EmployeeServiceImpl.java:22)
  com.application.controller.UserController.onSubmit(UserController.java:34)
  org.springframework.web.servlet.mvc.SimpleFormController.onSubmit(SimpleFormController.java:415)
  org.springframework.web.servlet.mvc.SimpleFormController.onSubmit(SimpleFormController.java:387)
  org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:272)
  org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:268)
  org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
  org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
  org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
  </code></pre>
  
  <p>Hibernate configuration file is</p>
  
  <p>Hibernate.cfg.xml</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
    &lt;session-factory&gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
      &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
      &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/employee_db&lt;/property&gt;
      &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
      &lt;property name="hibernate.connection.password"&gt;&lt;/property&gt;
      &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
      &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;
  
      &lt;mapping class="com.application.domain.Employee" /&gt;
    &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>dispatcher-servelet.xml</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:p="http://www.springframework.org/schema/p"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&gt;
  &lt;bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/&gt;
  
  &lt;!--
  Most controllers will use the ControllerClassNameHandlerMapping above, but
  for the index controller we are using ParameterizableViewController, so we must
  define an explicit mapping for it.
  --&gt;
  &lt;bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt;
      &lt;property name="mappings"&gt;
          &lt;props&gt;
              &lt;prop key="index.htm"&gt;indexController&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:prefix="/WEB-INF/jsp/"
        p:suffix=".jsp" /&gt;
  
  &lt;bean name="indexController"
        class="org.springframework.web.servlet.mvc.ParameterizableViewController"
        p:viewName="index" /&gt;
  
  &lt;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" 
  p:basename="messages" /&gt;
  &lt;bean id="employeeService" class="com.application.service.EmployeeServiceImpl" /&gt;
  &lt;bean id="employeeValidator" class="com.application.validator.EmployeeValidator" /&gt;
  &lt;bean name="userRegistration.htm" class="com.application.controller.UserController" 
      p:employeeService-ref="employeeService" p:formView="employeeForm" 
      p:successView="employeeSuccess" p:validator-ref="employeeValidator"/&gt;  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>After use the hibernet.cfg.xml from answer
  New Exception1</p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.application.util.HibernateUtil
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:839)
  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
  org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
  
  
  root cause 
  java.lang.NoClassDefFoundError: Could not initialize class com.application.util.HibernateUtil
  com.application.service.EmployeeServiceImpl.add(EmployeeServiceImpl.java:22)
  com.application.controller.UserController.onSubmit(UserController.java:34)
  org.springframework.web.servlet.mvc.SimpleFormController.onSubmit(SimpleFormController.java:415)
  org.springframework.web.servlet.mvc.SimpleFormController.onSubmit(SimpleFormController.java:387)
  org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:272)
  org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:268)
  org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
  org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
  org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
  </code></pre>
  
  <p>Are there any problem in this class
  EmployeeServiceImpl.java and HibernateUtil.java</p>
  
  <pre><code>public class EmployeeServiceImpl implements EmployeeService {
  
  @Override
  public void add(Employee employee) {
  //Persist the user object here. 
      Session session = HibernateUtil.getSessionFactory().openSession();
      Transaction transaction = null;
      try {
          transaction = session.beginTransaction();
          session.save(employee);
          transaction.commit();
      } catch (HibernateException e) {
          transaction.rollback();
      } finally {
          session.close();
      }
      System.out.println("User added successfully");
  }
  }
  
  public class HibernateUtil {
  private static final SessionFactory sessionFactory;
  static {
      try {
          sessionFactory = new Configuration().configure().buildSessionFactory();
      } catch (Throwable ex) {
          System.err.println("Initial SessionFactory creation failed." + ex);
          throw new ExceptionInInitializerError(ex);
      }
  }
  public static SessionFactory getSessionFactory() {
  return sessionFactory;
  }
  } 
  </code></pre>