title: How to Remove foreign key relation in table
body: <p>I have a part table which has part_id column and it is a FK in part_commnet table. Now my part table has grown very big, so I decided to remove some records into another table and created archive_parts table which is similar to part table. part table has a part_audit table also as hibernate-envers is implemented. Now my problem is if I want to remove records from the part table, it is not allowing me to do that as there is FK relation with part_comment and there is this part_audit table. So what is the best way to achieve this as I dont want to drop the FK relation in part_comment as it will change the nature of the table
  How can I hive out records from part table into archive_parts without losing the part_comments as I also want to restore the part record if required by the user without losing the part_comment. What is the best way to go about it.</p>
  <p>Part.java</p>
  <pre><code>@SuppressWarnings(&quot;serial&quot;)
  @Getter
  @Setter
  @NoArgsConstructor
  @AllArgsConstructor
  @ToString
  @Builder(toBuilder = true)
  @Entity
  @Audited(withModifiedFlag = true)
  @Table(name = &quot;part&quot;)
  public class Part extends AuditEntity {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = &quot;PART_ID&quot;)
      private Integer partId;
  
      @Column(name = &quot;part_number&quot;)
      private String partNumber;
  
      @Column(name = &quot;part_description&quot;)
      private String partDescription;
  
      @JsonIgnore
      //@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;ESN_ID&quot;, nullable = false)
      private Esn esn;
  
      @Column(name = &quot;quantity&quot;)
      private String quantity;
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;status_id&quot;)
      private Status status;
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;material_Stream_id&quot;, nullable = false)
      private MaterialStream materialStream;
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;source_id&quot;, nullable = false)
      private Source source;
  
      @Column(name = &quot;oem&quot;)
      private String oem;
  
      @Column(name = &quot;po_number&quot;)
      private String poNumber;
  
      @Column(name = &quot;manual_cso_commit&quot;)
      private Date manualCsoCommit;
  
      @Column(name = &quot;auto_cso_commit&quot;)
      private Date autoCsoCommit;
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;dr_status_id&quot;)
      private DrStatus drStatus;
  
      @Column(name = &quot;airway_bill&quot;)
      private String airwayBill;
  
      @Column(name = &quot;core_material&quot;)
      private Boolean coreMaterial;
  
      @Column(name = &quot;active&quot;)
      private Boolean active;
  
      @NotAudited
      @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
      @ToString.Exclude
      @EqualsAndHashCode.Exclude
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = &quot;part&quot;)
      private Set&lt;PartComment&gt; comments;
  
      @JsonIgnore
      @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;tenant_id&quot;)
      private Tenant tenant;
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;module_id&quot;)
      private Module module;
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;hpc_status_id&quot;)
      private HpcStatus hpcStatus;
  
      @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
      @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      @JoinTable(name = &quot;part_user_action&quot;, 
              joinColumns = @JoinColumn(name = &quot;part_id&quot;), 
              inverseJoinColumns = @JoinColumn(name = &quot;user_sso&quot;))
      @ElementCollection(targetClass=User.class)
      private List&lt;User&gt; actionUsers;
      
      @Column(name = &quot;ship_out&quot;)
      private Date shipOut;
      
      @Column(name = &quot;receipt&quot;)
      private Date receipt;
      
      @Column(name = &quot;crit_ship&quot;)
      private Boolean critShip; // Checkbox identify lines for Warehouse to expedite shipment
      
      @Column(name = &quot;late_call&quot;)
      private Boolean lateCall; // Checkbox to identify issues to identify RCCA for process.
      
      @Column(name = &quot;ex_esn&quot;)
      private String exEsn;
      
      @Column(name = &quot;accum_offset&quot;)
      private Integer accumOffset;
  
      @Column(name = &quot;po_line_num&quot;)
      private String poLineNum;
      
      @PrePersist
      @PreUpdate
      void init() {
          if (active == null)
              active = true;
          if (coreMaterial == null)
              coreMaterial = false;
          if (actionUsers == null)
              actionUsers = new ArrayList&lt;User&gt;();
          if (critShip == null)
              critShip = false;
          if (lateCall == null)
              lateCall = false;
          if (accumOffset == null)
              accumOffset = 0;
      }
  </code></pre>
  <p>Part_comment.java</p>
  <pre><code>@SuppressWarnings(&quot;serial&quot;)
  @Getter @Setter @NoArgsConstructor @AllArgsConstructor
  @Builder(toBuilder=true)
  @Entity
  @Table(name=&quot;part_comment&quot;)
  public class PartComment extends AuditEntity {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name=&quot;part_comment_id&quot;)
      private Integer partCommentId;
  
      @JsonIgnore
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;part_id&quot;, nullable=false)
      private Part part;
  
      @Column(name=&quot;comment&quot;)
      private String comment;
  }
  </code></pre>