title: Hibernate Composite key with database generated timestamp
body: <p>I'm having trouble saving an object with a composite primary key using Hibernate 3.3 and annotations. </p>
  
  <p>My key consists of a user's unique ID and a database generate Timestamp.</p>
  
  <p>How do I map this key using annotations? I've used some reverse engineering tools, but when I try to save the entity I run into problems.</p>
  
  <p>Example:</p>
  
  <pre><code>@Entity
  @Table(name = "ACTIVITY_LOG", schema = "WEB")
  public class ActivityLog implements java.io.Serializable {
  
      // Fields
  
      private ActivityLogId id;
      private SearchAuditRecord searchAuditRecord;
  
      // Constructors
  
           .....
  
      // Property accessors
      @EmbeddedId
      @AttributeOverrides({
          @AttributeOverride(name = "identifier", column = @Column(name = "IDENTIFIER", nullable = false, length = 11)),
          @AttributeOverride(name = "createTimestamp", column = @Column(name = "CREATE_TIMESTAMP", insertable=false, updatable=false, nullable = false, length = 26)) })
      public ActivityLogId getId() {
      return this.id;
      }
  
      public void setId(ActivityLogId id) {
      this.id = id;
      }
  
      .....
  
  }
  
  
  @Embeddable
  public class ActivityLogId implements java.io.Serializable {
  
      // Fields
  
      private String identifier;
      private Date createTimestamp;
  
      // Constructors
  
      /** default constructor */
  public ActivityLogId() {
      }
  
      /** full constructor */
      public ActivityLogId(String hrmisIdentifier, Date createTimestamp) {
      this.identifier = identifier;
      this.createTimestamp = createTimestamp;
  }
  
  // Property accessors
  
      @Column(name = "IDENTIFIER", nullable = false, length = 11)
      public String getIdentifier() {
          return this.identifier;
      }
  
      public void setIdentifier(String identifier) {
          this.identifier = identifier;
      }
  
  
      @Column(name = "CREATE_TIMESTAMP",insertable= false, updatable= false,  nullable = false, length = 26)
      public Date getCreateTimestamp() {
          return this.createTimestamp;
      }
  
      public void setCreateTimestamp(Timestamp createTimestamp) {
          this.createTimestamp = createTimestamp;
      }
  
  }
  </code></pre>
  
  <p>I figure I need to tell Hibernate that ActivityLogID.createTimestamp is being created by the Database... but I'm not sure how.</p>
  
  <p>As it stand right now, when I try to save theses objects I get:</p>
  
  <pre><code>org.hibernate.exception.ConstraintViolationException: 
  could not insert: [ca.gc.rcmp.persistence.ActivityLog]........ 
  Caused by: com.ibm.db2.jcc.am.fo: DB2 SQL Error: SQLCODE=-407, SQLSTATE=23502, SQLERRMC= , DRIVER=3.57.82
  </code></pre>
  
  <p>Which is telling me I can't put a null into a Not-null column. CreateTimestamp is the only field in my entity that is null.</p>
  
  <p>Any advice would be greatly appreciated. </p>
  
  <p>Thanks!</p>