title: Hibernate mapping error - Unknown entity
body: <p>I'm a hibernate newbie and im receiving this error when trying to persist an object - </p>
  
  <p>Error -->Unknown entity: org.apache.struts.register.model.Event</p>
  
  <p>In my <code>hibernate.cfg.xml</code>, I define my mapping as, </p>
  
  <p><code>&lt;mapping class="org.apache.struts.register.model.Event"/&gt;</code></p>
  
  <p>My event class - </p>
  
  <pre><code>package org.apache.struts.register.model;
  
  import org.hibernate.annotations.Entity;
  
  
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Table;
  
  @Entity
  @Table (name="event")
  
  public class Event {
  
      @Id
      @GeneratedValue ( strategy =  GenerationType.AUTO)
   private int eventId;
   private String eventName;
   private String eventDescription;
  
   public String getEventName() {
    return eventName;
   }
  
   public void setEventName(String eventName) {
    this.eventName = eventName;
   }
  
   public String getEventDescription() {
    return eventDescription;
   }
  
   public void setEventDescription(String eventDescription) {
    this.eventDescription = eventDescription;
   }
  
   public String toString(){
    return this.eventName + "," + this.eventDescription;
   }
  
  }
  </code></pre>
  
  <p>EventDAO - </p>
  
  <pre><code>package dao;
  
  
  import org.apache.struts.register.model.Event;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.Transaction;
  
  
  public class EventDAO {
  
      public static boolean registerEvent(Event u) {
  
           SessionFactory sf = HibernateUtil.getSessionFactory();
           Transaction t = null;
           try  {
           Session s  = sf.openSession();
           t = s.beginTransaction(); // start a new transaction
           s.persist(u);
           t.commit();  // commit transaction 
           return true;
           }
           catch(Exception ex) {
               System.err.println("Error --&gt;"  + ex.getMessage());
               if ( t!=null) t.rollback();  // rollback transaction on exception 
               return false;
           }
      }
  }
  </code></pre>
  
  <p><code>System.err.println("Error --&gt;"  + ex.getMessage())</code>, is the line that throws the exception.</p>
  
  <p>Thanks.</p>