How to "Select for Update"
Application Type
Traditional Web

I am designing a system where many users can update data at the same time.

So, while editing the data, I want to lock the data with "SelectForUpdate" to prevent updates from other users.

When designing an Entity, if the Identifier is deleted (a design in which multiple Attribute becomes a Primary Key), the Entity Function ("GetEntityForUpdate") will not be created.

How can I achieve the same locked "SELECT"?

Rank: #54

Hi Yu Sakurai,

OutSystems can only have one entity identifier so the way to support a key which is a composition of attributes, you need to have a unique identifier Id (Long Integer) and the index on the fields marked as Unique as you have on the screen. 

In order to do the GetEntityForUpdate, you will need to pass the Id which you can with an aggregate getting the record by the attributes that form the unique index (in your case ATT1 and ATT2).

In this case, you can guarantee that the ATT1 and ATT2 are indeed a unique index and use the GetEntityForUpdate to secure against concurrency.

Rank: #4088

Hi Yu,

In OutSystems, it's not possible to have composite keys. OutSystems promotes the use of surrogate keys, instead of natural keys, and with that approach there's no need to use composite keys. 

You can however simulate composite keys by adding a composite, unique index using the attributes which i can see you have already done. I don't it is possible what you want to achieve.

best regards,



First , if I get myself in your situation I wouldn't use those tricks to get a kind of key that is not normally supported by the platform. Usually things get problematic in the most unexpected ways. 

But if you insist you can add two fields to the entity , an UserId and a datetime  that have to be tested each time an update is performed. 

Build a SQL to bulk update those fields in all the records you want to "Select for Update " with the  UserId from the current user and current dateTime. 

When updating verify if the userId is equal to the the user "userId , if so update the record and clean those fields, if not don't update.

For this to work you have to think in a way to solve tow situations , what to do if the record is "occupied",  what to do with a record that is not released normally. But I think this can work .

Again, think twice before use that entity. 



Rank: #57030
Thank you everyone for your helpful advice.

I implemented it as shown in the attached image.

Rank: #299

Hi Yu,

If you have found the solution for your problem, please mark this post as resolved.

Thanks & Kind Regards,