title: Cascade persistence with HashMap
body: <p>My parent class:</p>
  
  <pre><code>@Entity
  public class FooParent 
  {
      @OneToMany(fetch=FetchType.LAZY,orphanRemoval=true,mappedBy="parent")
      @Cascade({org.hibernate.annotations.CascadeType.ALL})
      public Map&lt;FooChild,FooChild&gt; kids = new HashMap&lt;&gt;();
  
      @Id @GeneratedValue(strategy=GenerationType.TABLE)
      Integer id;
  
      public FooParent ()
      {
      }
  }
  </code></pre>
  
  <p>and child class:</p>
  
  <pre><code>@Entity
  public class FooChild 
  {
      @Id @GeneratedValue(strategy=GenerationType.TABLE)
      Integer id;
  
      @ManyToOne
      FooParent parent;
  
      public FooChild (FooParent parent)
      {
          this.parent=parent;
      }
  }
  </code></pre>
  
  <p>I'm finding that cascaded persistence only seems to apply to the <em>value</em> of a Map, not the <em>key</em>.  If I do this:</p>
  
  <pre><code>FooParent foo = new FooParent();
  FooChild kid1 = new FooChild(foo);
  FooChild kid2 = new FooChild(foo);
  foo.kids.put(kid1,kid2);
  hibSession.persist(foo);
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.cards.FooChild
  </code></pre>
  
  <p>If I persist() <code>kid1</code> before <code>foo</code>, then all works fine.  Also, if I change <code>kids</code> to <code>Map&lt;Integer,FooChild&gt;</code>, it works, as does List</p>
  
  <p>Is this a limitation, or is the something else I need to do in order to cascade persistence of a mapped Map key?</p>