Skip to content
Advertisement

Can not insert null object on One to One relation Spring boot | nested exception is .PersistentObjectException: detached entity passed to persist

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

Advertisement

Answer

Simple Solutions

{
    "empSts": "Active",
    "empRef": null,
    "probationDuration": "6",
    "allOrgMstGroupId": {
        "id": 1
    }, 
    "allOrgMstOrganizationId": null
}
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement