title: Hibernate 3 - MappingException - AnnotationConfiguration instance is required to use <mapping class="xxxxclass"/>
body: <p>I tried my hand at writing a simple Hibernate 3 java program - to fetch data from DB, it works just fine when i try to configure with an <code>hbm.xml</code> file but when i use a model class to configure the same, I face issues as below. 
  ie </p>
  
  <pre><code>&lt;mapping class="example.Pojo_Stock"/&gt;  
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>&lt;mapping resource="Pojo_Stock.hbm.xml" /&gt;
  </code></pre>
  
  <p>Although tried all related queries on stackoverflow (many marked as duplicate) but unable to find a solution. Kindly help</p>
  
  <pre><code>public class MainApp {
  
      private static SessionFactory factory; 
      public static void main(String[] args) {
          try{
              System.out.println("In Main method of MainApp...");
  
              Configuration configure=new Configuration();  
              configure.configure("hibernate.cfg.xml");
              factory = configure.buildSessionFactory();
  
              MainApp mainApp = new MainApp();
              mainApp.listDetails_Stock();
          }
          catch(Throwable ex){
  
              System.err.println("Failed to create sessionFactory object." + ex);
              throw new ExceptionInInitializerError(ex); 
  
          }
      }
  
      public void listDetails_Stock(){
          System.out.println("In listDetails_Stock method of MainApp...");
  
          Session session = factory.openSession();
          Transaction tx = null;
  
          try{
              tx = session.beginTransaction();
              List&lt;Pojo_Stock&gt; details = session.createQuery("FROM Pojo_Stock").list();
              for(Pojo_Stock detail : details){
                  System.out.print("\nStockId: " + detail.getStockId());
                  System.out.print("\nStockCode: " + detail.getStockCode());
                  System.out.print("\nStockName: " + detail.getStockName());
              }
              tx.commit();
          }
  
  
          catch (HibernateException e) {
              if (tx!=null) tx.rollback();
              e.printStackTrace(); 
          }finally {
              session.close(); 
          }
      }
  </code></pre>
  
  <p>the model class looks like</p>
  
  <pre><code>@Entity
  @Table(name = "STOCK")
  public class Pojo_Stock {
  
      int StockId;    
      String StockCode;
      String StockName; 
      // Getters &amp; Setters    
  }
  </code></pre>
  
  <p>and my hibernate config looks like below,</p>
  
  <p>
      </p>
  
  <pre><code>    &lt;property name="hibernate.dialect"&gt;
          org.hibernate.dialect.OracleDialect
      &lt;/property&gt;
      &lt;property name="hibernate.connection.driver_class"&gt;
          oracle.jdbc.driver.OracleDriver
      &lt;/property&gt;
  
      &lt;property name="hibernate.connection.url"&gt;
          jdbc:oracle:thin:@xxxx
      &lt;/property&gt;
      &lt;property name="hibernate.connection.username"&gt;
          xxxx
      &lt;/property&gt;
      &lt;property name="hibernate.connection.password"&gt;
          xxxx
      &lt;/property&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
      &lt;!-- List of XML mapping files --&gt;
      &lt;!--  &lt;mapping resource="Pojo_Stock.hbm.xml" /&gt; --&gt;
      &lt;mapping class="example.Pojo_Stock"/&gt; 
  &lt;/session-factory&gt;
  </code></pre>
  
  <p></p>
  
  <p>the error i get on my console is as below,</p>
  
  <pre><code>Failed to create sessionFactory object.org.hibernate.MappingException: An AnnotationConfiguration instance is required to use &lt;mapping class="example.Pojo_Stock"/&gt;
  Exception in thread "main" java.lang.ExceptionInInitializerError
      at example.MainApp.main(MainApp.java:28)
  Caused by: org.hibernate.MappingException: An AnnotationConfiguration instance is required to use &lt;mapping class="example.Pojo_Stock"/&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 tutorialspoint.example.MainApp.main(MainApp.java:19)
  </code></pre>
  
  <p>I tried to use <code>AnnotationConfiguration()</code> instead of <code>Configuration()</code> that does not work instead throws the below error,</p>
  
  <pre><code>Exception in thread "main" java.lang.IncompatibleClassChangeError: org.hibernate.cfg.Mappings
      at java.lang.ClassLoader.defineClass(ClassLoader.java:262)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:69)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:540)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:451)
      at java.net.URLClassLoader.access$300(URLClassLoader.java:79)
      at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:1038)
      at java.security.AccessController.doPrivileged(AccessController.java:314)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:429)
      at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:665)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:644)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:627)
      at java.lang.J9VMInternals.verifyImpl(Native Method)
      at java.lang.J9VMInternals.verify(J9VMInternals.java:85)
      at java.lang.J9VMInternals.initialize(J9VMInternals.java:162)
      at postgres.hibernate.lessons.MainApp.main(MainApp.java:28)
  </code></pre>