title: Spring Data JPA Foreign Key in Child not persisting
body: <p>I'm trying to use spring data CrudRepository to persist a parent entity that includes a few child entities, however I'm having trouble getting the foreign key constraint OID in the child table to save when I "save" the parent.</p>
  
  <p>So in the example below a call to the controller with the provided JSON would persist an Ocean and the 2 child Fish.  However the FK OID in the Fish table isn't being set.  </p>
  
  <p>Starting with the JSON request to the controller here is the code.
  JSON REQUEST</p>
  
  <pre><code>{
       "name":"Atlantic",
       "fishes": [
       {
           "name": "blue fin tuna"
       },
       {
          "name": "great white shark"
       }
       ]
  }
  </code></pre>
  
  <p>OCEAN ENTITY</p>
  
  <pre><code>@Entity
  public class Ocean {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private long oid;
  private String name;
  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = 
  "ocean")
  private Set&lt;Fish&gt; fishes; //yeah maybe a  bad example
  </code></pre>
  
  <p>FISH ENTITY</p>
  
  <pre><code>@Entity
  public class Fish {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private long fid;
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "oid", nullable = false, updatable = false, insertable = 
  true)
  private Ocean ocean;
  private String name;
  </code></pre>
  
  <p>CONTROLLER</p>
  
  <pre><code>@PostMapping("/god/ocean")
  public Ocean createOcean(@RequestBody Ocean ocean) throws BadRequestException 
  {
      LOG.info("createOcean()");
      return oceanDao.save(ocean);
  }
  </code></pre>
  
  <p>REPOSITORY</p>
  
  <pre><code>public interface IOceanDao extends CrudRepository&lt;Ocean, Long&gt; {
  }
  </code></pre>
  
  <p>MySql TABLES</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `mydb`.`OCEAN` (
  `OID` INT NOT NULL AUTO_INCREMENT COMMENT '',
  `NAME` VARCHAR(45) NOT NULL COMMENT '',
   PRIMARY KEY (`OID`)  COMMENT '');
  
  CREATE TABLE IF NOT EXISTS `mydb`.`FISH` (
  `FID` INT(11) NOT NULL AUTO_INCREMENT COMMENT '',
  `OID` INT(11) NULL  COMMENT '',
  `NAME` VARCHAR(45) NOT NULL COMMENT '',
  PRIMARY KEY (`FID`)  COMMENT '',
  CONSTRAINT `FK_OID`
  FOREIGN KEY (`OID`)
  REFERENCES `mydb`.`OCEAN` (`OID`));
  </code></pre>