title: Hibernate: Violation on cascade persist
body: <p>I have two classes, Order and Contact annotated as below</p>
  
  <pre><code>public class Order {
        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "order_id_gen")
        @Column(name = "id_order")
        private long id;
  
        @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
        @JoinColumn(name = "id_order")
        private List&lt;Contact&gt; contacts = new ArrayList&lt;&gt;();
  
  }
  
  public class Contact {
        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "order_contact_id_gen")
        @Column(name = "id_contact")
        private long id;
  
          @ManyToOne
          @JoinColumn(name = "id_order")
          private Order order;
  
  }
  </code></pre>
  
  <p>When I try to save the entire order with a JPA repository like</p>
  
  <pre><code>public interface OrderRepository extends JpaRepository&lt;Order, Long&gt; {}
  </code></pre>
  
  <p>using </p>
  
  <pre><code>orderRepository.save(order);
  </code></pre>
  
  <p>I get an exception </p>
  
  <pre><code>javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
      at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
  Caused by: org.postgresql.util.PSQLException: ERROR: the INSERT or the UPDATE on table "ms_contact" violates foreign key constraint "fk_4uonv9hs08picha25luywl3on"
  Detail: the key (id_order)=(602) is not present in "ms_order".
  </code></pre>
  
  <p>and contacts are not persisted.</p>