Olingo V2 - Referential Constraint check on entities' properties

32 Views Asked by At

I am using Olingo 2.0.11 on top of Hibernate. I've built relationship between entities and the navigation property works fine by define the @OneToOne annotation to entities' properties:

public class MetaClass {
@OneToOne(mappedBy = "metaClassEntity", cascade = {CascadeType.MERGE, CascadeType.REFRESH}, optional = false)
private MetaClassReport metaClassReport;
}

public class MetaClassReport {
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = MetaClass.class)
@JoinColumns({
            @JoinColumn(name = "meta_class", referencedColumnName = "id", insertable = false, updatable = false),
            @JoinColumn(name = "tenant_id", referencedColumnName = "tenant_id", insertable = false, updatable = false)})
    private MetaClass metaClassEntity;
}

and the Edm looks like (notice the navigation property):

<EntityType Name="MetaClassReport">
                <Key>
                    <PropertyRef Name="Id"></PropertyRef>
                    <PropertyRef Name="TenantId"></PropertyRef>
                </Key>
                <Property Name="AppCode" Type="Edm.String" Nullable="true" MaxLength="50"></Property>
                <Property Name="CreateTime" Type="Edm.DateTime" Nullable="false"></Property>
                <Property Name="Creator" Type="Edm.String" Nullable="false" MaxLength="36"></Property>
                <Property Name="DataRelation" Type="Edm.String" Nullable="true" MaxLength="20"></Property>
                <Property Name="Id" Type="Edm.String" Nullable="false" MaxLength="22"></Property>
                <Property Name="JoinGeneral" Type="Edm.String" Nullable="true" MaxLength="255"></Property>
                <Property Name="Links" Type="Edm.String" Nullable="true" MaxLength="255"></Property>
                <Property Name="MainEntity" Type="Edm.String" Nullable="true" MaxLength="22"></Property>
                <Property Name="MetaClass" Type="Edm.String" Nullable="false" MaxLength="22"></Property>
                <Property Name="MicroServiceCode" Type="Edm.String" Nullable="true" MaxLength="50"></Property>
                <Property Name="Modifier" Type="Edm.String" Nullable="true" MaxLength="36"></Property>
                <Property Name="ModifyTime" Type="Edm.DateTime" Nullable="true"></Property>
                <Property Name="QuerySchema" Type="Edm.String" Nullable="true" MaxLength="22"></Property>
                <Property Name="Version" Type="Edm.Int32" Nullable="false"></Property>
                <Property Name="TenantId" Type="Edm.String" Nullable="false" MaxLength="36"></Property>
                <NavigationProperty Name="MetaClassDetails" Relationship="default.MetaClass_MetaClassReport_One_One0" FromRole="MetaClassReport" ToRole="MetaClass"></NavigationProperty>
            </EntityType>

            <Association Name="MetaClass_MetaClassReport_One_One0">
                <End Type="default.MetaClass" Multiplicity="1" Role="MetaClass"></End>
                <End Type="default.MetaClassReport" Multiplicity="0..1" Role="MetaClassReport"></End>
                <ReferentialConstraint>
                    <Principal Role="MetaClass">
                        <PropertyRef Name="Id"></PropertyRef>
                        <PropertyRef Name="TenantId"></PropertyRef>
                    </Principal>
                    <Dependent Role="MetaClassReport">
                        <PropertyRef Name="MetaClass"></PropertyRef>
                        <PropertyRef Name="TenantId"></PropertyRef>
                    </Dependent>
                </ReferentialConstraint>
            </Association>

Now I have the requirement to do the referential check when update MetaClassReport associated to a MetaClass by:

localhost:8080/odata/MetaClassReports

and the body is:

{
    "Id": "7s",
    "YtenantId": "1qaz2wsx",
    "Links": "",
    "Version": 1,
    "CreateTime": "2022-12-31T18:59:59",
    "Creator": "chenhem",
    "MetaClassDetails": {
        "Id": "5s",
        "YtenantId": "1qaz2wsx",
        "LegacyId": "12121212",
        "TableName": "classTable",
        "TableType": 0,
        "Uri": "aa.bb.testmetaclass",
        "Name": "testmetaclass",
        "MetaComponentId": "11111111111",
        "Version": 1,
        "CreateTime": "2022-12-31T18:59:59",
        "Creator": "chenhem"
    }
}

then I notice that Olingo would not check the reference constraint between MetaClass and MetaClass report, the MetaClass will be inserted into DB no matter the "MetaClass":"1s" exists in MetaClass table or not.

I am wondering if the <ReferentialConstraint> in Edm is just an illustration, or indeed it will do some effects just because I missed some configuration or implementation?

If the <ReferentialConstraint> is just a metadata illustration, then how should I implement such a key reference value check? (DB foreign key is not an option for me), thanks in advance.

0

There are 0 best solutions below