🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
ChangeTime
This page was created by Stephanie on 2024-05-23. Last edited by Wikiadmin on 2026-07-29.

ChangeTime is a DateTime attribute you can map to a database column when your model needs to store a change timestamp.

Use ChangeTime in persistence mapping

In the persistence-mapping example, ChangeTime is mapped as an attribute on persistent classes. The mapping associates the model attribute with a database column named ChangeTime.

<AttributeDef Name="ChangeTime" Alias="Class1_A" Columns="ChangeTime" AttributeMapper="&lt;Default&gt;" />

The corresponding database column is a required DATETIME column with the default value '19000101' in that example:

<Column Name="ChangeTime" AllowNULL="False" Type="DATETIME"
        DefaultValue="'19000101'" />

Use persistence mapping to review how model attributes, class aliases, and database columns are connected.

ChangeTime and CreateTime

The example maps both ChangeTime and CreateTime as DATETIME attributes. Use distinct attributes when your data model needs to retain both values.

Attribute Purpose in the mapping example
ChangeTime A required DateTime value stored in the ChangeTime database column.
CreateTime A separate required DateTime value stored in the CreateTime database column.

For example, a class mapped to the Class1 table can have both columns:

<AttributeDef Name="ChangeTime" Alias="Class1_A" Columns="ChangeTime" AttributeMapper="&lt;Default&gt;" />
<AttributeDef Name="CreateTime" Alias="Class1_A" Columns="CreateTime" AttributeMapper="&lt;Default&gt;" />

Inherited mapping example

When a subclass is child-mapped, inherited attributes can be stored in the child class table. In the supplied mapping example, Class4 maps inherited ChangeTime and CreateTime attributes to its own table:

<AttributeDef Name="ChangeTime" Alias="Class4_A" Columns="ChangeTime" AttributeMapper="&lt;Default&gt;" />
<AttributeDef Name="CreateTime" Alias="Class4_A" Columns="CreateTime" AttributeMapper="&lt;Default&gt;" />

The Class4 table therefore includes both DATETIME columns. See Working with Code and Persistence Mapping for the complete child-mapping example.

Do not confuse ChangeTime with version history

A ChangeTime attribute is a mapped DateTime value. It is not the same thing as a versioning change point. If versioning is enabled on a class, use changePoints to retrieve stored historical versions within a timestamp range.

For example, the following OCL expression retrieves recorded versions of the first Customer from the beginning of recorded history through the latest version:

Customer.allInstances->first.changePoints(0, -1)

Date and time types

Use a DateTime value when you need to edit or store a date. If you need only a time part or a duration, use a TimeSpan value instead; see Date vs Time. To convert a string to a TimeSpan value in OCL, see strToTime.

See also