title: Initial SessionFactory creation failed: java.lang.NoClassDefFoundError: javax/persistence/NamedStoredProcedureQuery
body: <blockquote>
    <p><strong>SOLVED</strong></p>
  </blockquote>
  
  <p>What did i do to solve it?</p>
  
  <p>I added the <code>Persistence JPA2.1</code> to the library</p>
  
  <p>Initial error</p>
  
  <p>I'm having this <strong>error</strong>:</p>
  
  <pre><code>Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: javax/persistence/NamedStoredProcedureQuery
  Exception in thread "main" java.lang.ExceptionInInitializerError
  at modelo.util.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:29)
  at modelo.dao.GenericDAO.getAll(GenericDAO.java:89)
  at principal.Main.main(Main.java:34)
  Caused by: java.lang.NoClassDefFoundError: javax/persistence/NamedStoredProcedureQuery
  at org.hibernate.cfg.AnnotationBinder.bindDefaults(AnnotationBinder.java:276)
  at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1402)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
  at modelo.util.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:25)
  ... 2 more
  Caused by: java.lang.ClassNotFoundException: javax.persistence.NamedStoredProcedureQuery
  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  ... 7 more
  </code></pre>
  
  <p>Have no idea why I'm getting that exception</p>
  
  <p><strong>Main</strong> class:</p>
  
  <pre><code>public class Main {
  
  /**
   * @param args the command line arguments
   */
      public static void main(String[] args) {
         GenericDAO clienteDAO = new GenericDAO();
         List&lt;Cliente&gt; list = clienteDAO.getAll(Cliente.class);
         System.out.println(list.size());
         for(Cliente c : list)
           {System.out.println("-&gt; " + c.getNombre());
         } 
       }
  }
  </code></pre>
  
  <p><strong>HibernateUtil</strong> class:</p>
  
  <pre><code>public class HibernateUtil {
  
  private static final SessionFactory sessionFactory;
  
  static {
      try {
          // Create the SessionFactory from standard (hibernate.cfg.xml) 
          // config file.
          sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
      } catch (Throwable ex) {
          // Log the exception. 
          System.err.println("Initial SessionFactory creation failed." + ex);
          throw new ExceptionInInitializerError(ex);
      }
  }
  
  public static SessionFactory getSessionFactory() {
      return sessionFactory;
  }
  }
  </code></pre>
  
  <p>Mapping <strong>Class.hbm.xml</strong> file:</p>
  
  <pre><code> &lt;?xml version="1.0"?&gt;
   &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
       "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt;
   &lt;!-- Generated 21/05/2017 17:46:05 by Hibernate Tools 4.3.1 --&gt;
   &lt;hibernate-mapping&gt;
  &lt;class name="modelo.pojo.Cliente" table="cliente" catalog="basededatosprueba" optimistic-lock="version"&gt;
      &lt;id name="codigo" type="java.lang.Integer"&gt;
          &lt;column name="codigo" /&gt;
          &lt;generator class="identity" /&gt;
      &lt;/id&gt;
      &lt;property name="nombre" type="string"&gt;
          &lt;column name="nombre" /&gt;
      &lt;/property&gt;
      &lt;property name="direccion" type="string"&gt;
          &lt;column name="direccion" /&gt;
      &lt;/property&gt;
      &lt;property name="telefono" type="string"&gt;
          &lt;column name="telefono" /&gt;
      &lt;/property&gt;
      &lt;property name="cuit" type="string"&gt;
          &lt;column name="cuit" /&gt;
      &lt;/property&gt;
      &lt;property name="cp" type="java.lang.Integer"&gt;
          &lt;column name="cp" /&gt;
      &lt;/property&gt;
      &lt;property name="saldo" type="java.lang.Double"&gt;
          &lt;column name="saldo" precision="22" scale="0" /&gt;
      &lt;/property&gt;
      &lt;property name="deuda" type="java.lang.Double"&gt;
          &lt;column name="deuda" precision="22" scale="0" /&gt;
      &lt;/property&gt;
  &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>my <strong>hibernate.cfg.xml</strong></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="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
  &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/basededatosprueba?zeroDateTimeBehavior=convertToNull&lt;/property&gt;
  &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
  &lt;property name="hibernate.current_session_context_class"&gt;org.hibernate.context.internal.ThreadLocalSessionContext&lt;/property&gt;
  &lt;mapping resource="modelo/pojo/Cliente.hbm.xml"/&gt;
  &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p><strong>libraries</strong> 
  <a href="https://i.stack.imgur.com/8qwGD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8qwGD.png" alt="enter image description here"></a></p>
  
  <p>I don't know why I'm getting that error.</p>
  
  <p>Hope someone can help me. Thanks</p>