title: What are reasonable scenarios to use GenerationTime.INSERT in the Hibernate @Generated annotation?
body: <p>I wonder about the behavior of Hibernate regarding fields annotated with <strong>@Generated(value=GenerationTime.INSERT)</strong> when I do an update on the entity. </p>
  
  <p>I have an entity with the following fields (which are populated by database triggers, the first one on insert, the second one on insert and for each update):</p>
  
  <pre><code>@Generated(value = GenerationTime.INSERT)
  @Column(name="created_by", insertable = false, updatable = false)
  private String createdBy;
  
  @Generated(value = GenerationTime.ALWAYS) 
  @Column(name="updated_by", insertable = false, updatable = false)
  private String updatedBy;
  </code></pre>
  
  <ul>
  <li>When I load an entity from the database, both fields are populated - as expected </li>
  <li>When I receive the entity back from the web-ui, both fields will be null - as expected since they weren't bound to any form field.</li>
  </ul>
  
  <p>After calling </p>
  
  <pre><code>sessionFactory.getCurrentSession().saveOrUpdate(object);
  </code></pre>
  
  <p>the createdBy field will be null but the updatedBy field will be set to the correct value (created by the database).</p>
  
  <p>So the entity no longer contains the values from the database - an undesired behavior. </p>
  
  <p>For my situation can solve the issue
  - I could change the GenerationTime to ALWAYS - but this seems to be confusing since createdBy is really only set  when the entity is inserted.
  - I could do a refresh on the entity - but I would like to avoid the extra call.</p>
  
  <ol>
  <li>What is the best practice for the described situation? <strong>Are there better options that avoid an explicit call of refresh and don't obscure the semantic of fields modified only on insert?</strong></li>
  <li><strong>What are reasonable scenarios to use @Generated(value=GenerationTime.INSERT)?</strong></li>
  </ol>