title: Hibernate mapping exception
body: <p>I am getting the below error on trying to save an <code>Employee</code> object to database:</p>
  
  <pre><code>org.hibernate.MappingException: Unknown entity: com.example.common.Employee
      at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:597)
      at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1339)
  </code></pre>
  
  <p><strong>Dependencies in <em>pom.xml</strong> related to hibernate [Mine is a Spring-Hibernate project]</em>**</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate&lt;/artifactId&gt;
      &lt;version&gt;3.2.7.ga&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
      &lt;version&gt;4.3.4.Final&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
      &lt;version&gt;5.1.0.Final&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
      &lt;version&gt;3.2.2.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>I used to define Hibernate mappings in mapping XML file. With this example, I was trying with annotations.</p>
  
  <p><strong>Employee.java</strong>  [only the beginning portion of code]</p>
  
  <p>I am including the import statements too </p>
  
  <pre><code>import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.FetchType;
  import javax.persistence.Id;
  import javax.persistence.ManyToMany;
  import javax.persistence.OneToMany;
  import javax.persistence.Table;
  import javax.validation.Valid;
  import javax.validation.constraints.NotNull;
  import javax.validation.constraints.Size;
  
  import org.hibernate.validator.constraints.NotEmpty;
  
  @Entity
  @Table(name = "employees")
  public class Employee implements Serializable {
      private static final long serialVersionUID = 5468763051360122059L;
  
      @Id
      @Column(name = "employee_guid", length = 36)
      @NotNull
      @Size(min = 36, max = 36)
      private String id;
  
      @Column(name = "is_active", nullable = false)
      private boolean isActive;
  
      @ManyToMany(mappedBy = "employees", fetch = FetchType.LAZY, cascade = {
              CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH
      })
  </code></pre>
  
  <p>I tried changing <code>@Enitiy</code> to <code>@org.hibernate.annotations.Entity</code> too, but of no use. </p>
  
  <p>Please give me some hint on where I am wrong. Please let me know if you need more code.</p>
  
  <p><strong>Edit:</strong> </p>
  
  <p>Let me know how to specify Employee Entity bean here?</p>
  
  <pre><code>&lt;bean id="MyHibernateSessionFactory"
          class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="mappingResources"&gt;
              &lt;!-- if there is a mapping file like Employee.hbm.xml i can refer here, but i manage thru annotations --&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;create&lt;/prop&gt;
                  &lt;prop key="hibernate.connection.autocommit"&gt;false&lt;/prop&gt;
                  &lt;prop key="hibernate.connection.isolation"&gt;2&lt;/prop&gt;
                  &lt;prop key="hibernate.transaction.auto_close_session"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.current_session_context_class"&gt;managed&lt;/prop&gt;
                  &lt;prop key="hibernate.transaction.flush_before_completion"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.H2Dialect&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>I am trying with this one</p>
  
  <pre><code>&lt;property name="annotatedClasses"&gt;
              &lt;list&gt;
                  &lt;value&gt;com.example.Employee&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
  </code></pre>
  
  <p>Also changed : <code>class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;</code></p>
  
  <p><strong>Update:</strong></p>
  
  <p>This question is incomplete unless more code is shared. Hence closing this for now, with the below suggestion as answer, though it is not the exact answer I was looking for. Will reopen when I get a chance. Thanks all.</p>