title: NHibernate (Hibernate) Auto Increment On Property
body: <p>Using nHibernate (or Hibernate as the mapping does not differ), I want to create an object with the following SQL:</p>
  
  <pre><code>CREATE TABLE `table` (
      `EntityId` binary(16) NOT NULL,
      `Number` int(11) NOT NULL AUTO_INCREMENT,
      PRIMARY KEY (`EntityId`),
      Key(`Number`)
  );
  </code></pre>
  
  <p>Ive tried using generated properties, additional id tags, specifying the sqltype in column tags under the property tags, and messing with defaults, insert, update, and not null attributes but nothing seems to work. Am I just not able to map this in Hibernate mapping syntax? How can I get a property that is not the primary key to auto increment?</p>
  
  <p>I would post the mappings Ive got but none of them work. </p>
  
  <p>Thanks in advance</p>
  
  <p><strong>Update:</strong>
  Using this mapping which I think is a good starting point but not quite what I want:</p>
  
  <pre><code>&lt;class name="TheEntity" table="table"&gt;
  
    &lt;id name="Id" 
       column="EntityId"
       generator="guid.comb" /&gt;
  
    &lt;property name="Number" 
              generated="insert"
              insert="false" update="false" /&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>The schema in the database is generated as such:</p>
  
  <pre><code>CREATE TABLE `table` (
    `EntityId` binary(16) NOT NULL,
    `Number` int(11) DEFAULT NULL,
    PRIMARY KEY (`EntityId`)
  );
  </code></pre>
  
  <p>which is not the desired behavior. Nor does nHibernate, through some means, insert a sequence into Number. Generated Properties, as shown above, from what Ive read rely on the database taking care of the insertion and updating entirely through something like a trigger. I do not want to use a trigger to do something as basic as auto_increment however since there is a built in facility already for this.</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks again in advance.</p>