title: Hibernate @OneToOne child not persisting
body: <p>I have a Stock entity which has 2 child entities, stock can only be vehicle or property, not both, stock is defined as follows:</p>
  
  <pre><code>@RooJavaBean
  @RooToString
  @RooJpaActiveRecord
  public class Stock {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "id")
      private Long id;
  
      @Version
      @Column(name = "version")
      private Integer version;
  
      ...
  
      @OneToOne(mappedBy = "stock", cascade = CascadeType.ALL)
      private StockProperty property;
      private Boolean isProperty;
  
      @OneToOne(mappedBy = "stock", cascade = CascadeType.ALL)
      private StockVehicle vehicle;
      private Boolean isVehicle;
  
      ....
  
  }
  </code></pre>
  
  <p>And then the child entity StockProperty:</p>
  
  <pre><code>@RooJavaBean
  @RooToString
  @RooJpaActiveRecord
  public class StockProperty {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "id")
      private Long id;
  
      @Version
      @Column(name = "version")
      private Integer version;
  
      ....
  
      @PrimaryKeyJoinColumn
      @OneToOne(cascade = CascadeType.ALL)
      private Stock stock;
  
      ... more fields containing property details
  
  }
  </code></pre>
  
  <p>StockVehicle follows exactly the same pattern:</p>
  
  <pre><code>@RooJavaBean
  @RooToString
  @RooJpaActiveRecord
  public class StockVehicle {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "id")
      private Long id;
  
      @Version
      @Column(name = "version")
      private Integer version;
  
      ....
  
      @PrimaryKeyJoinColumn
      @OneToOne(cascade = CascadeType.ALL)
      private Stock stock;
  
      ... more fields containing vehicle details
  
  }
  </code></pre>
  
  <p>When trying to link the two, it's always null in the database:</p>
  
  <pre><code>Stock stock = new Stock();
  stock.setProperty(new StockProperty());
  stock.getProperty().persist();
  stock.persist();
  </code></pre>
  
  <p>Or the other way around, it's still null on both sides:</p>
  
  <pre><code>Stock stock = new Stock();
  
  ... fill in stock details
  
  StockProperty property = new StockProperty();
  property.setStock(stock);
  ... fill in property details
  
  stock.setProperty(property);
  stock.persist();
  
  property.persist();
  </code></pre>
  
  <p>I'm not seeing any errors in the logs, but the linking just never happens:</p>
  
  <p>Stock's propery fields are all null:</p>
  
  <p><img src="https://i.stack.imgur.com/NPbCi.png" alt="enter image description here"></p>
  
  <p>StockProperty's stock fields are all null:</p>
  
  <p><img src="https://i.stack.imgur.com/8TIKZ.png" alt="enter image description here"></p>
  
  <p>I'm trying to implement a cascade delete, so when I'm deleting Stock, it must delete StockProperty and if possible, the other way around as well, otherwise I would have made it a one-directional reference.</p>
  
  <p>Update SQL as requested:</p>
  
  <pre><code>Hibernate: insert into stock (account, company, created, full_description, ..., is_property, is_vehicle, modified, version) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
  
  Hibernate: select last_insert_id()
  
  Hibernate: insert into stock_property (created, modified, ... , version) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
  
  Hibernate: select last_insert_id()
  </code></pre>
  
  <p>I don't see the property field in the stock insert sql, neither do I see the stock field in the insert sql for stock_property.</p>