title: Cascade within @EmbeddedId in hibernate
body: <p>I'm adding an intersection table with additional data and I use <strong>@EmbeddedId</strong> to make a complex ID for the entities which are bound by the record in this table(<em>entity1</em> and <em>entity2</em>). </p>
  
  <p>I want to save all the data via cascade when I save entity 1. So, that is why in entity 1 I have:</p>
  
  <pre><code>@OneToMany(cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH},
              fetch = FetchType.LAZY, mappedBy = "id.entity1")
  private List&lt;Entity1ToEntity2Link&gt; links = new ArrayList&lt;&gt;();
  </code></pre>
  
  <p>In Entity1ToEntity2Link I have @EmbeddedId and within it I have links to both entities. But, I want the second one to be saved when I save entity 1. So, I made it like this:</p>
  
  <pre><code>@ManyToOne(cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
  private Entity2 entity2;
  </code></pre>
  
  <p>But, unfortunatelly, the cascade that I have inside @EmbeddedId seems to be ignored. I can see that sql for insert is not generated and when Entity1ToEntity2Link is saved I get an error:</p>
  
  <blockquote>
    <p>violated - parent key not found</p>
  </blockquote>
  
  <p>I suspect that @EmbeddedId doesn't support cascades. But, I'm not sure. Do you have any ideas how I can save entity2 before Entity1ToEntity2Link is saved? </p>
  
  <hr>
  
  <p>Id object:</p>
  
  <pre><code>@Embeddable
  public class LinkId extends AbstractLinkId {
      //...
      @ManyToOne(cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
      private Entity2 entity2;
      //...
  }
  
  
  @MappedSuperclass
  public class AbstractLinkId {
      //...
      @ManyToOne
      private Entity1 entity1;
      //...
  }
  </code></pre>