Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-14299

Confusing API when deleting Liferay entities

    Details

      Description

      e.g. OrganizationLocalServiceBaseImpl implements two methods for deleting organizations:

      • deleteOrganization(long organizationId)
      • deleteOrganization(Organization organization)

      By default, these methods forward to the persistence's delete methods, that will only remove a row in the Organization database table.

      However, the deleteOrganization(long organizationId) is overwritten in OrganizationLocalServiceImpl, a subclass of OrganizationLocalServiceBaseImpl. In this overwritten method, links with other tables (group, resource, phone number, etc.) are removed as well, which is desired behaviour to leave the database tables consistent.

      Because OrganizationLocalServiceImpl doesn't overwrite deleteOrganization(Organization org), if you call that method in OrganizationLocalServiceUtil, only the organization record will be removed and not all its references, causing stale data to be left behind. At least, deleteOrganization(Organization org) should be overwritten as well in OrganizationLocalServiceImpl, OR (even better) there should be only one method for entity deletion, that is overwritten in the service as required.

      This behaviour does not only exist for organizations, but for almost all Liferay entities. It is very easy for developers to, by mistake, call the "wrong" delete service method and cause data inconsistency. This error is very hard to trace as well. We discovered the issue on a client that is almost a year in production now.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                3 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  8 years, 39 weeks, 5 days ago

                  Packages

                  Version Package
                  --Sprint 12/11
                  6.1.0 CE RC1