title: How to set the column order of a composite primary key using JPA/Hibernate
body: <p>I'm having trouble with the ordering of the columns in my composite primary key.  I have a table that contains the following:</p>
  
  <pre><code>@Embeddable
  public class MessageInfo implements Serializable {
  
      private byte loc;
      private long epochtime;
  
      @Column(name = "loc")
      public byte getLoc() {
          return loc;
      }    
  
      @Column(name = "epochtime")
      public long getEpochtime() {
          return epochtime;
      }
  }
  </code></pre>
  
  <p>It is used in this mapping:</p>
  
  <pre><code>@MappedSuperclass
  @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  public abstract class AbstractMessage implements Message {
  
      private MessageInfo info;
      private int blah;
  
      @EmbeddedId
      public MessageInfo getInfo() {
          return info;
      }
  }
  </code></pre>
  
  <p>When I subclass AbstractMessage with a concrete @Table class hibernate creates the database and table with no errors.  The problem is that hibernate is generating the composite primary key with the columns in the reverse order of what I would like.</p>
  
  <pre><code>CREATE TABLE  `mydb`.`concrete_table` (
    `epochtime` bigint(20) NOT NULL,
    `loc` tinyint(4) NOT NULL,
    `blah` smallint(6) DEFAULT NULL,
    `foo` smallint(6) DEFAULT NULL,
    PRIMARY KEY (`epochtime`,`loc`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  </code></pre>
  
  <p>I want the primary key to be </p>
  
  <pre><code>PRIMARY KEY (`loc`,`epochtime`)
  </code></pre>
  
  <p>Since I know that I will have a maximum of 10 loc's, but many epochtimes for each loc.</p>
  
  <p>Any help would be appreciated =)</p>