title: Going "behind Hibernate's back" to update foreign key values without an associated entity
body: <p><strong>Updated</strong>: I wound up "solving" the problem by doing the opposite! I now have the entity reference field set as read-only (insertable=false updatable=false), and the foreign key field read-write. This means I need to take special care when saving new entities, but on querying, the entity properties get resolved for me.</p>
  
  <hr>
  
  <p>I have a bidirectional one-to-many association in my domain model, where I'm using JPA annotations and Hibernate as the persistence provider.  It's pretty much your bog-standard parent/child configuration, with one difference being that I want to expose the parent's foreign key as a separate property of the child alongside the reference to a parent instance, like so:</p>
  
  <pre><code>@Entity
  public class Child {
      @Id @GeneratedValue
      Long id;
  
      @Column(name="parent_id", insertable=false, updatable=false)
      private Long parentId;
  
      @ManyToOne(cascade=CascadeType.ALL)
      @JoinColumn(name="parent_id")
      private Parent parent;
  
      private long timestamp;
  }
  
  @Entity
  public class Parent {
      @Id @GeneratedValue
      Long id;
  
      @OrderBy("timestamp")
      @OneToMany(mappedBy="parent", cascade=CascadeType.ALL, fetch=FetchType.LAZY)
      private List&lt;Child&gt; children;
  }
  </code></pre>
  
  <p>This works just fine most of the time, but there are many (legacy) cases when I'd like to put an invalid value in the parent_id column without having to create a bogus Parent first.</p>
  
  <p>Unfortunately, Hibernate won't save values assigned to the <code>parentId</code> field due to <code>insertable=false, updatable=false</code>, which it requires when the same column is mapped to multiple properties. Is there any nice way to "go behind Hibernate's back" and sneak values into that field without having to drop down to JDBC or implement an interceptor?</p>
  
  <p>Thanks!</p>