title: Setting a JPA timestamp column to be generated by the database?
body: <p>In my SQL Server 2000 database, I have a timestamp (in function not in data type) column of type <code>DATETIME</code> named <code>lastTouched</code> set to <code>getdate()</code> as its default value/binding.</p>
  
  <p>I am using the Netbeans 6.5 generated JPA entity classes, and have this in my code</p>
  
  <pre><code>@Basic(optional = false)
  @Column(name = "LastTouched")
  @Temporal(TemporalType.TIMESTAMP)
  private Date lastTouched;
  </code></pre>
  
  <p>However when I try to put the object into the database I get, </p>
  
  <pre><code>javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.generic.Stuff.lastTouched
  </code></pre>
  
  <p>I've tried setting the <code>@Basic</code> to <code>(optional = true)</code>, but that throws an exception saying the database doesn't allow <code>null</code> values for the <code>TIMESTAMP</code> column, which it doesn't by design.</p>
  
  <pre><code>ERROR JDBCExceptionReporter - Cannot insert the value NULL into column 'LastTouched', table 'DatabaseName.dbo.Stuff'; column does not allow nulls. INSERT fails.
  </code></pre>
  
  <p>I previously got this to work in pure Hibernate, but I have since switched over to JPA and have no idea how to tell it that this column is supposed to be generated on the database side. Note that I am still using Hibernate as my JPA persistence layer.</p>