title: Unable to create unique key constraint
body: <p>I am creating a simple entity and trying to persist it to Oracle database. Here is my enitity:</p>
  
  <pre><code>import java.io.Serializable;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.Table;
  import javax.persistence.UniqueConstraint;
  
  @Entity
  @Table(name = "TBL_FLIGHT", uniqueConstraints = @UniqueConstraint(name = "flight_number", columnNames = {
          "comp_prefix", "flight_number" }))
  public class Flight implements Serializable {
      @Id 
      private Long id;
      private String companyPrefix;
      private String number;
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public void setCompanyPrefix(String companyPrefix) {
          this.companyPrefix = companyPrefix;
      }
  
      public void setNumber(String number) {
          this.number = number;
      }   
  
      @Column(name = "comp_prefix")
      public String getCompanyPrefix() {
          return companyPrefix;
      }
  
      @Column(name = "flight_number")
      public String getNumber() {
          return number;
      }
  }
  </code></pre>
  
  <p>Here is my Java class that creates an instance of this entity and saves it to database using Hibernate:</p>
  
  <pre><code>public class AppTest{
  
      public static void main(String[] args) {
  
          Session session = HibernateUtil.getSessionFactory().getCurrentSession();
          session.beginTransaction();
  
          Flight flight = new Flight();
          flight.setCompanyPrefix("prefix");;
          flight.setNumber("100");
          flight.setId(1L);
          session.save(flight);
  
          session.getTransaction().commit();          
  
          HibernateUtil.getSessionFactory().close();
      }
  }
  </code></pre>
  
  <p>When I run this program then I am getting an exception as :</p>
  
  <pre><code>Caused by: org.hibernate.AnnotationException: Unable to create unique key constraint (comp_prefix, flight_number) on table TBL_FLIGHT: database column 'comp_prefix', 'flight_number' not found. Make sure that you use the correct column name which depends on the naming strategy in use (it may not be the same as the property name in the entity, especially for relational types)
      at org.hibernate.cfg.Configuration.buildUniqueKeyFromColumnNames(Configuration.java:1682)
      at org.hibernate.cfg.Configuration.buildUniqueKeyFromColumnNames(Configuration.java:1614)
      at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1450)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
  </code></pre>
  
  <p>Please help where I am making mistake in this code. I am using <code>Hibernate-4.3.6</code></p>
  
  <p>Update: Here is my hibernate configuration file, the table gets generated by hibernate itself:</p>
  
  <p>
  </p>
  
  <p></p>
  
  <pre><code>&lt;session-factory&gt;
  
      &lt;!-- Database connection settings --&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:@localhost:1521:XE&lt;/property&gt;
      &lt;property name="hibernate.connection.username"&gt;myuser&lt;/property&gt;
      &lt;property name="hibernate.connection.password"&gt;mypasswd&lt;/property&gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/property&gt;
  
      &lt;!-- JDBC connection pool (use the built-in) --&gt;
      &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
  
      &lt;!-- Enable Hibernate's automatic session context management --&gt;
      &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
  
      &lt;!-- Disable the second-level cache --&gt;
      &lt;property name="cache.provider_class"&gt;org.hibernate.cache.internal.NoCacheProvider&lt;/property&gt;
  
      &lt;!-- Echo all executed SQL to stdout --&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
      &lt;!-- Drop and re-create the database schema on startup --&gt;
      &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
  
      &lt;mapping class="org.hibernate.tutorial.Flight" /&gt;
  &lt;/session-factory&gt;
  </code></pre>
  
  <p></p>
  
  <p>Also if possible please suggest me a good resource for Hibernate-4.3, because the <a href="http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/index.html" rel="noreferrer">online document</a> is not a good resource for starters like me.</p>