title: Cannot delete or update a parent row - JPA with Hibernate
body: <p>I have a database in which all of the tables have been generated by Java JPA/Hibernate code. I need to update several tables in my database in a fashion similar to this,</p>
  
  <pre><code>UPDATE Department SET id=100000 WHERE id=0;
  </code></pre>
  
  <p>Unfortunately this results in the error</p>
  
  <blockquote>
    <p>ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (departmentuserlink, CONSTRAINT FK96AF44EAB09C41C5 FOREIGN KEY (department_id) REFERENCES department (id))</p>
  </blockquote>
  
  <p>Here are the Java entities:</p>
  
  <pre><code>@Entity
  @Table(name="Department")
  public class Department extends AbstractEntity implements IAbstractEntity {
  
  @OneToMany(cascade=CascadeType.ALL, mappedBy="department", fetch=FetchType.EAGER)
  private Set&lt;DepartmentJobLink&gt; departmentJobs = new HashSet&lt;DepartmentJobLink&gt;(0);
  
      //Setters &amp; getters and all that
  }
  
  
  
  @Entity
  @Table(name="edrDepartmentJobLink",     uniqueConstraints={@UniqueConstraint(columnNames={"department_id", "job_id"})})
  public class DepartmentJobLink extends AbstractEntity implements IAbstractEntity {
  
  @ManyToOne(fetch=FetchType.EAGER)
  @JoinColumn(name="department_id", nullable=false)
  private Department department;
  
      //Setters &amp; getters and all that
  }
  </code></pre>
  
  <p>They both have ID's in the superclass. So far it looks like everything else about them works great, just running into trouble with updating the primary key of Department. I would appreciate any advice. Thanks.</p>