title: Is there any way to declare final fields for Hibernate-managed objects?
body: <p>I'm just getting started with Hibernate, and all the examples I'm seeing so far look pretty much like the tutorial in the Hibernate documentation:</p>
  
  <pre><code>package org.hibernate.tutorial.domain;
  import java.util.Date;
  
  public class Event {
  
      private Long id;
      private String title;
      private Date date;
  
      public Event() {}
  
      /* Accessor methods... */
  }
  </code></pre>
  
  <p>Specifically: none of the fields are declared as <code>final</code>, and there must be a no-argument constructor so that the Hibernate framework can instantiate the class and set its fields.</p>
  
  <p>But here's the thing - I <strong>really</strong> don't like making my classes mutable in any way whenever I can avoid it (Java Practices: Immutable Objects make a pretty strong argument for doing this).  So <em>is there any way to get Hibernate to work even if I were to declare each of the fields 'final'</em>?</p>
  
  <p>I understand that Hibernate uses Reflection to instantiate its classes and therefore needs to be able to invoke a constructor of some sort without taking the risk that it would pick the wrong constructor or pass the wrong value to one of its parameters, so it's probably safer to invoke the no-arg constructor and set each field one at a time.  However, shouldn't it be possible to provide the necessary information to Hibernate so that it can safely instantiate immutable objects?</p>
  
  <pre><code>public class Event {
  
      private final Long id;
      private final String title;
      private final Date date;
  
      public Event(@SetsProperty("id") Long id,
          @SetsProperty("title") String title,
          @SetsProperty("date") Date date) {
  
          this.id = id;
          this.title = title;
          this.date = new Date(date.getTime());
      }
  
      /* Accessor methods... */
  }
  </code></pre>
  
  <p>The <code>@SetsProperty</code> annotation is of course fictitious, but doesn't seem like it should be out of reach.</p>