🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators IsNew
This page was created by Lars.olofsson on 2018-04-10. Last edited by Wikiadmin on 2026-07-29.

IsNew lets you test in OCL whether the current object has never been saved to the database; use it when a rule or expression must behave differently for newly created objects.

Syntax

self.isNew

The expression returns a Boolean value:

Result Meaning
true The object has never been saved to the database.
false The object has been saved to the database at least once.

Example: Fruit

Assume that your model contains a class named Fruit.

Use the following expression when the current Fruit must be identified as new:

self.isNew

For a newly created Fruit that has not yet been saved, the expression evaluates to true. After that Fruit has been saved to the database, the same expression evaluates to false.

IsNew and IsDirty

Do not use IsNew to test whether an existing object was edited. An object can have been saved before and then changed afterwards; it is not new, but it is dirty. Use IsDirty to test whether an object has changed since its last save.

Situation self.isNew IsDirty meaning
A new Fruit has not been saved true Use IsDirty when you need to test for changes since the last save.
An existing Fruit is changed after it was saved false The object has changed since its last save.
An existing Fruit has no changes after its last save false The object has not changed since its last save.

Use in an OCL expression

Enter the expression in the OCL Editor in the context of the class you want to test. For example, when the expression context is Fruit, use self.isNew to test that Fruit instance.

For an overview of available operators, see Documentation:OCL General Operators. For logical expressions that combine Boolean results, see Documentation:OCL Boolean Operators.

See also