title: Hibernate Mapping Error: MappingException: An AnnotationConfiguration instance
body: <p>I have a project with Hibernate.I tried to read the configuration file hibernate.cfg and got this error:</p>
  
  <pre><code> Error creando una factoria de session.org.hibernate.MappingException: An AnnotationConfiguration instance is required to use &lt;mapping class="com/david/Categoria"/&gt;
  jun 04, 2013 10:19:26 AM org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: El Servlet.service() para el servlet [ControladorLibros] en el contexto con ruta [/App01HTML] lanzó la excepción [La ejecución del Servlet lanzó una excepción] con causa raíz
  org.hibernate.MappingException: An AnnotationConfiguration instance is required to use &lt;mapping class="com/david/Categoria"/&gt;
      at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1524)
      at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1479)
      at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1458)
      at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1432)
      at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
      at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)
      at com.david.HibernateHelper.buildSessionFactory(HibernateHelper.java:13)
  </code></pre>
  
  <p>my configuration file is so simple:</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;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="connection.url"&gt;jdbc:mysql://localhost/arquitecturajava&lt;/property&gt;
          &lt;property name="connection.username"&gt;root&lt;/property&gt;
          &lt;property name="connection.password"&gt;root&lt;/property&gt;
          &lt;property name="connection.pool_size"&gt;5&lt;/property&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQL5Dialect&lt;/property&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;mapping class="com/david/Categoria"&gt;&lt;/mapping&gt;
          &lt;mapping class="com/david/Libro"&gt;&lt;/mapping&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>don´t accept mapping class lines.</p>
  
  <p>I create de configurations similar to this code:</p>
  
  <pre><code>private static SessionFactory buildSessionFactory() 
      {
          try
          {
  
              return new Configuration().configure().buildSessionFactory(); 
          }
          catch (Throwable ex) 
          {
              System.err.println("Error creando una factoria de session." + ex);
              throw new ExceptionInInitializerError(ex);
          }
      }
  </code></pre>
  
  <p>and my project libraries are:</p>
  
  <p><img src="https://i.stack.imgur.com/uq7Dp.png" alt="enter image description here"></p>
  
  <p>Any idea?</p>