title: HIbernate Can't delete Entity with foreign key. Foreign key gets set to null
body: <p>This question has been asked in many forms here but none of the solutions seem to work for me. I'm trying to delete the parent entity and I want all of the child entities to also be deleted.</p>
  
  <p>My entities:</p>
  
  <pre><code>@Entity
  @Table(name = "item", catalog = "myshchema")
  public class Item implements java.io.Serializable {
  
  @JoinColumn(name = "item_id", insertable = false, updatable = false, nullable = false)
  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
  private Set&lt;ItemCategory&gt; categories;
  
  /* Getters and Setters and other fields*/
  }
  </code></pre>
  
  <p>Table for Item:</p>
  
  <pre><code>CREATE TABLE `item` (
  `item_id` int(11) NOT NULL AUTO_INCREMENT,
  `store_id` int(11) NOT NULL,
  PRIMARY KEY (`item_id`),
  UNIQUE KEY `item_id_UNIQUE` (`item_id`),
  KEY `FK_ITEM_STORE_ID_idx` (`store_id`),
  CONSTRAINT `FK_ITEM_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `store`   (`store_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
  ) ENGINE=InnoDB AUTO_INCREMENT=84 DEFAULT CHARSET=utf8;
  </code></pre>
  
  <p>And my other entity</p>
  
  <pre><code>@Entity
  @Table(name = "item_category", catalog = "myschema")
  @IdClass(ItemCategoryIndex.class)
  public class ItemCategory implements java.io.Serializable {
  
  @Id
  @Column(name = "category_id", unique = true, nullable = false, insertable = false, updatable = false)
  private Integer categoryId;
  @Id
  private Store store;
  @Id
  private Item item;
  @Id
  private String categoryName;
  
  /* Getters and Setters */
  }
  </code></pre>
  
  <p>Table for ItemCategory:</p>
  
  <pre><code>CREATE TABLE `item_category` (
  `category_id` int(11) NOT NULL AUTO_INCREMENT,
  `store_id` int(11) NOT NULL,
  `item_id` int(11) NOT NULL,
  `category_name` varchar(45) NOT NULL,
  PRIMARY KEY (`category_id`),
  UNIQUE KEY `category_id_UNIQUE` (`category_id`),
  UNIQUE KEY `IDX_UNIQUE_STORE_CATEGORY`     (`store_id`,`item_id`,`category_name`) USING BTREE,
  KEY `FK_CATEGORY_STORE_ID_idx` (`store_id`),
  KEY `FK_ITEM_CATEGORY_ID_idx` (`item_id`),
  CONSTRAINT `FK_CATEGORY_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES     `store` (`store_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `FK_ITEM_CATEGORY_ID` FOREIGN KEY (`item_id`) REFERENCES `item`     (`item_id`) ON DELETE CASCADE ON UPDATE NO ACTION
  ) ENGINE=InnoDB AUTO_INCREMENT=162 DEFAULT CHARSET=utf8;
  </code></pre>
  
  <p>I try to delete the item like this:  </p>
  
  <pre><code>Item item = entityManager.find(Item.class, idList.get(i));
  entityManager.remove(item);
  </code></pre>
  
  <p>My logs show that Hibernate is trying to set the primary key for ItemCategory to null: </p>
  
  <pre><code>Hibernate: update myschema.item_category set item_id=null where item_id=?
  ERROR o.h.e.jdbc.spi.SqlExceptionHelper.logExceptions 146 - Column 'item_id' cannot be null
  </code></pre>
  
  <p>I even tried looping through the child records and deleting them manually, but Hibernate still issues this update to null query.  What am I doing wrong?</p>