Conflicted with the REFERENCE constraint FK

Hi,

I am getting this exception while deleting record from screen, This is because current entity is having field ID which is having a foreign key as SubID in another table.
So If I delete SubId first then it will work but how can I remove the dependency of FK so that I can delete it directly from the screen?

image

You can Set the “on delete” Option to “cascade” of the foreign key field.

https://doc.cuba-platform.com/manual-6.3/delete_policy.html

Hi,

I am getting below error while setting on delete to cascade:

Execution failed for task ':LOA-global:enhance'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_161\bin\java.exe'' finished with non-zero exit value 1

Below are the code:

package com.sompo.intl.legal.loa.entity;

import javax.persistence.Entity;
import javax.persistence.Table;
import com.haulmont.chile.core.annotations.NamePattern;
import com.haulmont.cuba.core.global.DeletePolicy;
import com.haulmont.cuba.core.global.DesignSupport;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import com.haulmont.cuba.core.entity.BaseIntegerIdEntity;
import com.haulmont.cuba.core.entity.annotation.OnDelete;
import java.util.List;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.validation.constraints.NotNull;

@NamePattern("%s %s|undFirst,undLast")
@DesignSupport("{'imported':true}")
@Table(name = "UnderwritersIns")
@Entity(name = "loa$UnderwritersIns")
public class UnderwritersIns extends BaseIntegerIdEntity {
    private static final long serialVersionUID = -3460063408051135600L;

    @Column(name = "\"UndFirst\"")
    protected String undFirst;

    @NotNull
    @Column(name = "BSIC", nullable = false)
    protected Boolean bsic = false;

    @NotNull
    @Column(name = "SAFM", nullable = false)
    protected Boolean safm = false;

    @NotNull
    @Column(name = "LIC", nullable = false)
    protected Boolean lic = false;

    @NotNull
    @Column(name = "SAIC", nullable = false)
    protected Boolean saic = false;

    @OneToMany(mappedBy = "subID")
    @OrderBy("ord ASC")
    @OnDelete(DeletePolicy.CASCADE)
    protected List<GRSIndusIns> grsIndustries;

    @OneToMany(mappedBy = "subID")
    @OrderBy("orderNum ASC")
    @OnDelete(DeletePolicy.CASCADE)
    protected List<RestClassIns> businessRestrictions;

    @OneToMany(mappedBy = "subID")
    @OrderBy("order ASC")
    @OnDelete(DeletePolicy.CASCADE)
    protected List<LOBsIns> coverageRestrictions;

    @OneToMany(mappedBy = "subID")
    @OrderBy("type ASC, order ASC")
    @OnDelete(DeletePolicy.CASCADE)
    protected List<CorpRTSUndIns> corporateRestrictions;

    @OneToMany(mappedBy = "subID")
    @OrderBy("order ASC")
    @OnDelete(DeletePolicy.CASCADE)
    protected List<AuthorizedProgramsIns> authorizedProgramStructures;

Is there anything need to do at DDL level also?

@OnDelete and @OnDeleteInverse annotations affect only entities implementing SoftDelete interface. For hard-deleted entities the @OnDeleteInverse annotation indicates to Studio (since v.6.7) that it should generate an appropriate cascade clause for the foreign key.

Your entity seems to be imported from an existing database, so how to create such foreign key in your table depends on how you work with the DDL of this database.

Hi Konstatine,

By doing so (Enabling Soft Delete and using annotation @OnDelete on foreign key)
I am getting below exception:
SQLServerException: Invalid column name 'DELETE_TS'.

Soft deleted entities require the specific set of columns in the table: DELETE_TS and DELETED_BY