Home > Net >  Can not insert null object on One to One relation Spring boot | nested exception is .PersistentObjec
Can not insert null object on One to One relation Spring boot | nested exception is .PersistentObjec

Time:09-28

This is the relation

   @OneToOne(optional = true, fetch = FetchType.LAZY, cascade = CascadeType.PERSIST )
    @JoinColumn(name = "ALL_ORG_MST_ORGANIZATION_ID")
    private AllOrgMst allOrgMstOrganizationId;

And postman Object Data

{
    "empSts": "Active",
    "empRef": null,
    "probationDuration": "6",
    "allOrgMstGroupId": {
        "id": 1
    },
    "allOrgMstOrganizationId": {
        "id": null
    }
}

I can not insert null value .If I give the AllOrgMstOrganizationId then no problem.But when I give it Null Then Error::org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist: com.hrms.entity.com.AllOrgMst; nested exception is org.hibernate.PersistentObjectException: detached entity passed to persist: com.hrms.entity.com.AllOrgMst

CodePudding user response:

You have to change the value of field allOrgMstOrganizationId from empty object to null. Maybe this will solve your problem. The dataset be like bellow:

{
    "empSts": "Active",
    "empRef": null,
    "probationDuration": "6",
    "allOrgMstGroupId": {
        "id": 1
    }, 
    "allOrgMstOrganizationId": null
}
  • Related