title: Hibernate component mapping of an immutable object
body: <p>I have an immutable object which is a member of a Hibernate persisted object using component mapping. Example, <code>PinDrop</code> corresponds to a table, which has a field of type immutable <code>Point</code>:</p>
  
  <pre><code>public class PinDrop {
      private String name;
      private Point location;
      // Getters and setters for name and location
  }
  
  // Immutable Point
  public class Point {
      private final double x;
      private final double y;
      // Getters for x and y, no setters
  }
  </code></pre>
  
  <p>In my <code>PinDrop.hbm.xml</code>:</p>
  
  <pre><code>&lt;property name="name" column="name" type="string"/&gt;
  &lt;component name="location" class="Point&gt;
      &lt;property name="x" column="location_x" type="double"/&gt;
      &lt;property name="y" column="location_y" type="double"/&gt;
  &lt;/component&gt;
  </code></pre>
  
  <p>This doesn't work because at runtime Hibernate complains that <code>Point</code> doesn't have setters for <code>x</code> and <code>y</code>. Is there a way to use an immutable object as a component of a Hibernate persistent object?</p>
  
  <p><strong>Follow-up</strong>: I'm not using annotations, but rather <code>hbm.xml</code>. Neither <code>mutable</code> nor <code>immutable</code> are valid attributes on <code>component</code> and <code>property</code> in <code>hbm.xml</code>.</p>