🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators allInstances
This page was created by Alexandra on 2017-08-08. Last edited by Wikiadmin on 2026-07-29.

You can use allInstances in OCL to retrieve every existing instance of a model class, including instances of its subclasses.

Syntax and return value

ClassName.allInstances
Item Description
Receiver A class in your model, such as Complaint.
Return type Set{T}, where T is the receiving class.
Result All existing instances of that class and instances of classes that inherit from it.

Retrieve all instances of a class

For example, this expression returns the set of all existing Complaint objects:

Complaint.allInstances

You can continue with collection operations to select or inspect objects. For example, the following expression takes one Complaint from the returned set and returns its broken constraint names:

Complaint.allInstances->first.brokenConstraints

See brokenConstraints for details about inspecting violated constraints.

Inheritance is included

allInstances includes objects of inherited classifiers (subclasses). If Fruit is a superclass and Mango inherits from it, Fruit.allInstances includes both Fruit instances and Mango instances.

Use the type operations superTypes and allSuperTypes when you need to examine the inheritance hierarchy itself rather than retrieve object instances.

Choose the correct operator

allInstances retrieves all existing objects of the class. It is different from allLoadedObjects, which returns only objects currently loaded in memory and does not load additional objects from the database.

Need Use
All existing objects of a class, including subclass objects ClassName.allInstances
Only objects currently loaded in the application ClassName.allLoadedObjects
Objects as they existed at a historical point in time ClassName.allInstancesAtTime(timeStamp)

Find operators in the OCL Editor

To explore operations available for a class:

  1. Open the OCL Editor.
  2. Type the name of a model class, for example Complaint.
  3. Use the editor's available operations to find applicable operators.

For the general operator overview, see Documentation:OCL General Operators.

See also