title: Hibernate: Unknown entity exception during first launch of a program
body: <p>I started learning Hibernate, so I decided to start with simple program. I have a class:</p>
  
  <p>Video:</p>
  
  <pre><code>package org.media;
  
  import javax.persistence.Column;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  
  import org.hibernate.annotations.Entity;
  import org.hibernate.annotations.Table;
  
  @Entity
  @Table(appliesTo="video")
  public class Video {
  @Id
  @Column(name="id")
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;
  @Column(name="description", length=64)
  private String description;
  
  //getters and setters...
  }
  </code></pre>
  
  <p>My hibernate.cfg.xml file looks like:</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="hibernate.connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
      &lt;property name="hibernate.connection.username"&gt;postgres&lt;/property&gt;
      &lt;property name="hibernate.connection.password"&gt;1&lt;/property&gt;
      &lt;property name="hibernate.connection.url"&gt;jdbc:postgresql://localhost:5432/media&lt;/property&gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/property&gt;
      &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
      &lt;property name="hibernate.hb2ddl.auto"&gt;update&lt;/property&gt;
      &lt;mapping class="org.media.Video" /&gt;
  &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>I have a method that adds simple record to DB:</p>
  
  <pre><code>public void addVideo(String description) {
      Session session = HibernateUtil.getSessionFactory().getCurrentSession();
      session.beginTransaction();
      Video video = new Video();
      video.setDescription(description);
      session.save(video);
      session.getTransaction().commit();
  }
  </code></pre>
  
  <p>And when I launch my program, it crashes on this method with exception:</p>
  
  <pre><code>Exception in thread "main" org.hibernate.MappingException: Unknown entity: org.media.Video
  </code></pre>
  
  <p>There's a corresponding tables in my DB with a name and columns like in annotations. What is wrong with it?</p>
  
  <p>Thank you in advance.</p>