code: private void removeMemberships(Node membershipTypeNode) throws Exception
     {
        PropertyIterator refTypes = membershipTypeNode.getReferences();
        while (refTypes.hasNext())
        {
           Property refTypeProp = refTypes.nextProperty();
  
           Node refTypeNode = refTypeProp.getParent();
           Node refUserNode = refTypeNode.getParent();
  
           membershipHandler.removeMembership(refUserNode, refTypeNode);
        }
     }
docs: Removes related membership entity.