title: Hibernate mapping with ID generated by DB trigger + sequence
body: <p>everyone.
  I've a LOG table with a combination of trigger and sequence to create the id, so when I insert the line I do not have to specify the id, otherwise the database returns error. However Hibernate claims (rightly) that was specified primary key.</p>
  
  <p><strong>What kind of "generator" property should I use in this case?</strong></p>
  
  <p>I already tried "<strong>assigned</strong>" it says:</p>
  
  <pre><code>org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save (): it.m2sc.simulator.beans.Log
  </code></pre>
  
  <p>With "<strong>select</strong>" hib ask me the natural key, but there is no natural key in this table, but the primary.</p>
  
  <pre><code>org.hibernate.id.IdentifierGenerationException: no natural-id property defined; need to specify [key] in generator parameters
  </code></pre>
  
  <p>That's my hbm</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="it.m2sc.simulator.beans.Log" table="LOG"&gt;
          &lt;id name="id" type="integer" column="LOG_ID" access="field"&gt;
              &lt;generator class="select" /&gt; 
          &lt;/id&gt;
          &lt;property name="date" type="date" column="LOG_DATE" access="field" /&gt;
          &lt;property name="user" type="string" column="LOG_USER" access="field" /&gt;
          &lt;property name="evtId" type="integer" column="EVT_ID" access="field" /&gt;
          &lt;property name="detail" type="string" column="LOG_DETAIL" access="field" /&gt;
          &lt;property name="deleted" type="character" column="LOG_DELETED" access="field" /&gt;
          &lt;property name="codiceRaggruppamento" column="LOG_CODICE_RAGGRUPPAMENTO" type="string" access="field" /&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>The Class</p>
  
  <pre><code>public class Log {
      private Integer id;
      private Date date;
      private String user;
      private Integer evtId;
      private String detail;
      private Character deleted = '0';
      private String codiceRaggruppamento;
  
      ... ( getter &amp; setter )
  }
  </code></pre>
  
  <p>DDL of table/trigger/sequence</p>
  
  <pre><code>CREATE TABLE
      LOG
      (
          LOG_ID NUMBER(12) NOT NULL,
          LOG_DATE TIMESTAMP(6),
          LOG_USER VARCHAR2(50),
          EVT_ID NUMBER(12),
          LOG_DETAIL VARCHAR2(100),
          LOG_DELETED CHAR(1) DEFAULT '0 ' NOT NULL,
          LOG_CODICE_RAGGRUPPAMENTO NCHAR(2) NOT NULL,
          CONSTRAINT LOG_PK PRIMARY KEY (LOG_ID),
          CONSTRAINT LOG_CFG_EVENT_TYPE_FK1 FOREIGN KEY (EVT_ID)
          REFERENCES CFG_EVENT_TYPE (EVT_ID)
      );
  
     CREATE SEQUENCE  LOG_SEQ  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 358 CACHE 20 NOORDER  NOCYCLE;
  
  CREATE OR REPLACE TRIGGER "DTCUSR"."LOG_TRG" BEFORE INSERT ON LOG
  FOR EACH ROW
  BEGIN
    &lt;&lt;COLUMN_SEQUENCES&gt;&gt;
    BEGIN
      IF :NEW.LOG_ID IS NULL THEN
        SELECT LOG_SEQ.NEXTVAL INTO :NEW.LOG_ID FROM DUAL;
      END IF;
    END COLUMN_SEQUENCES;
  END;
  </code></pre>
  
  <p>Ah, just fyi: db is Oracle11</p>
  
  <p>Ty in advice</p>