title: No cascade insert for child with foreign key on parent
body: <p>I have checked many posts on the internet and none address my problem. Really appreciate if anyone can help!
  I have OneToMany parent child relationship. Hibernate does not cascade insert child (Level2) when one of the child composite keys is the foreign key to the parent (Level1). I specified cascade="all" and no matter the inverse is true or false, the results are the same. There is no exception, and it simply does not insert. Below print out shows Level1 was inserted successfully but Level2 was only selected, no insert.</p>
  
  <pre><code>Hibernate: insert into sst.level_1 (STATUS, NAME) values (?, ?)
  Hibernate: select level2x_.LEVEL_1_ID, level2x_.TIMESEGMENT, level2x_.CATEGORY as CATEGORY4_ from sst.level_2 level2x_ where level2x_.LEVEL_1_ID=? and level2x_.TIMESEGMENT=?
  </code></pre>
  
  <p>The APIs are Hibernate 4.1.6/Spring 3.1.2.</p>
  
  <p>Here is the table definition for mySQL:</p>
  
  <pre><code>CREATE TABLE level_1
  (
  ID int NOT NULL PRIMARY KEY AUTO_INCREMENT,
  STATUS int,
  NAME varchar(255)
  );
  
  CREATE TABLE level_2
  (
  LEVEL_1_ID int,
  TIMESEGMENT int,
  CATEGORY varchar(2),
  PRIMARY KEY (LEVEL_1_ID, TIMESEGMENT),
  FOREIGN KEY (LEVEL_1_ID) REFERENCES level_1(ID) ON DELETE CASCADE
  );
  </code></pre>
  
  <p>Here is the test code.</p>
  
  <pre><code>public class Test {
  
     public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        doInsert(context);
     }
  
     private static void doInsert(ApplicationContext context) {
  
        Level1 level1 = new Level1();
        Level2 level2 = new Level2();
  
        level1.setName("LEVEL 1 NAME");
        level1.setStatus(1);
        level1.getLevel2s().add(level2);
  
        level2.setLevel1(level1);
        level2.setCategory("CA");
        level2.setId(new Level2Id(level1.getId(), 10));
  
        Level1DAO level1DAO = (Level1DAO) context.getBean("Level1DAO");
        level1DAO.save(level1);
     }
  }
  </code></pre>
  
  <p>Mapping for Level1:</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="com.jc.hibernate.Level1" table="level_1" catalog="sst"&gt;
          &lt;id name="id" type="java.lang.Integer"&gt;
              &lt;column name="ID" /&gt;
              &lt;generator class="identity" /&gt;
          &lt;/id&gt;
          &lt;property name="status" type="java.lang.Integer"&gt;
              &lt;column name="STATUS" /&gt;
          &lt;/property&gt;
          &lt;property name="name" type="java.lang.String"&gt;
              &lt;column name="NAME" /&gt;
          &lt;/property&gt;
          &lt;set name="level2s" inverse="true" cascade="all"&gt;
              &lt;key&gt;
                  &lt;column name="LEVEL_1_ID" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;one-to-many class="com.jc.hibernate.Level2" /&gt;
          &lt;/set&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Mapping for Level2:</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="com.jc.hibernate.Level2" table="level_2" catalog="sst"&gt;
          &lt;composite-id name="id" class="com.jc.hibernate.Level2Id"&gt;
              &lt;key-property name="level1Id" type="java.lang.Integer"&gt;
                  &lt;column name="LEVEL_1_ID" /&gt;
              &lt;/key-property&gt;
              &lt;key-property name="timesegment" type="java.lang.Integer"&gt;
                  &lt;column name="TIMESEGMENT" /&gt;
              &lt;/key-property&gt;
          &lt;/composite-id&gt;
          &lt;many-to-one name="level1" class="com.jc.hibernate.Level1" update="false" insert="false" fetch="select"&gt;
              &lt;column name="LEVEL_1_ID" not-null="true" /&gt;
          &lt;/many-to-one&gt;
          &lt;property name="category" type="java.lang.String"&gt;
              &lt;column name="CATEGORY" length="2" /&gt;
          &lt;/property&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>