OCLOperators setToNull
Created by Hans.karlsen on 2018-07-13 · Last edited by Vale.buyondo on 2026-02-16.
The setToNull operator is an Executable Action Language (EAL) command that explicitly clears the value of a nullable attribute or a single-link association (0..1). It is the programmatic way to assign a database NULL to a field.
Syntax
[Object].[NullableProperty].setToNull
Example
Order.allinstances->first.OrderDate.setToNull
The OrderDate for that specific order is wiped and becomes empty.
You can also use the assign operator := and assign <Type>.nullValue to get the same effect.
| Error Message | Cause | Solution |
| "setToNull can only be applied to nullable attributes" | Mandatory Property: The attribute or association is marked as "Required" or multiplicity "1" in the model. | In the Class Diagram, under Mode "Allow Null" box in the properties should be set to true or change multiplicity to 0..1.
|
| "setToNull can only be applied to nullable attributes" | Collections: You are trying to use it on a list (0..*) instead of a single object. | Use the ->clear operator to empty a list.
|
