Question
· Feb 22, 2023

Using UUID as primary key

Hello,

Comming back to Cache after some long gap. Is it possible to use UUID  as primary key while creing a Persistant class (Not using the default numerical ID)?

and creating the relationships also using UUID?

Product version: IRIS 2022.2
Discussion (5)3
Log in or sign up to continue

Personally I'd rather use a default numeric ID and if needed an additional UUID/GUID unique property.

To implement what you asked you can use something like:

Class My.TestClass Extends %Persistent
{
Property PrimaryUUID As %String [ InitialExpression = {$system.Util.CreateGUID()} ];
Property MyOtherData As %String;

Index PrimaryUUIDIndex On PrimaryUUID [ IdKey, Unique ];
}

In this way the primary key (PrimaryUUID) is automatically assigned, no need to set it manually, in SQL is mapped as ID (as well as PrimaryUUID).

Enrico