Impact of using database record locks

Hi Everybody, One of your customers needs locking of database records: when a second employee opens a record that a first employee is already editing, a message should be displayed or a readonly version. I have seen this topic -> and am testing with the locking-feature in the community commons package (Michel Weststrate, thanks!) I now need to now the impact (and if available some tips and tricks for implementing this) Is it just an acquireLock() when an Edit button is fired and a releaseLock when the save or cancel button is used? Does this indeed mean that all edit, all save and all cancel-buttons have to be changed to microflows (instead of normal buttons)? Can I use event-handlers here (after rollback -> release lock)* are there any other consequences, tips and tricks or pittfals? Thanks in forward! As far as I see, eventhandlers cannot be used, because then I cannot have parameters in my Microflow, to "know" which record should be released
6 answers

Hi Roberto,

regarding question 2a), in 2.5.3 we can implement this behavior without using persistent session, but then I need to update the community commons package.

2b). The system logs user automatically out after 5 minutes after the browser has been closed. In combination with 2a, this means that the lock will be released within 5 minutes after the browser close/ crash.

However note that if somebody opens a window, and then leaves his computer for 8 hours without closing his browser or session, he will have the lock for that 8 hours.

We just released version 1.2 of the library; locks will be removed automatically after an session has expired or was killed somehow.

  1. true
  2. true
  3. Why cant you use after rollback event? It passes the object which is rollbacked..
  4. :

a) First of all, I did not test it extensively.

b) One pitfall is that currently if you are not using persistent sessions (which is the default), locks will not be released automatically if a session ends without releasing the lock (for example when you open an edit form and then kill the browser). If you change to Mendix 2.5.3 I can solve this issue since 2.5.3 has better session management support.

c) Note that when exceptions occur, you still need to release the locks.

d) Note that certain client widgets (inline datagrids for example) might directly modify your object, without looking at the locks.


FYI: I filed a Feature Request for this topic (nr 7774).

The communitycommons method seem to work OK, but for 2 reasons I would like this functionality in the Modeler (automated) for the following reason:

Modeling the record lock has quite an impact: - Firstly because modelling this functionality takes quite some time in several screens - Secondly because now this record-locking functionality must be modelled, the risk of making errors is quite high

The proposal is that this functionality can be activated by either
- Application-wide set "recordlocking" to enabled (which means that only 1 person can open a record)
- Per grid (datagrid, reference set and template grid) enable / disable recordLocking (if you don't want to have it active application-wide)


After discussing this issue with the customer that requested this, I have the following remarks / questions:

1) Our customer was very surprised that it's no central feature of Mendix, since Mendix is a Web-based tool, wich often is multi-user, with higher risk of overwriting eachothers records... What is the experience of others in this area: do many of you need this functionality? Or do most of you not need this? I'm wondering!

2) For our customer it is needed is that when a record is locked due to a crash or browser-close, after 30 (or 15?) minutes, this is released, to make sure that things are accessible without interference of an administrator. a: If I want to have this, do I then need persistent sessions*?
b: If the release-time is 15 or 30 minutes and I for some reason need 35 minutes time for editing a record: am I also logged out automatically, or has the login-system nothing to do with it?

I hope there is some additional advice and I wonder about others expieriencing (or not experiencing!) this problem...

  • I do not know the exact details of persistent sessions, but heard people that advised me not to use it for security reasons?


I have updated to the new "Community Commons Function Library v1.2" and implemented the lock-mechanism in the application. As far as I can see it works fine, so thanks!

Two questions:
Is it true that a lock will not be removed when I open a record on computer A (and have called acquireLock() on the opening) and then browse away to an entirely other web-page, but do NOT close my browser...? As far as I can test, the record will not be released automatically in this case, can this be confirmed?

I think on the production-environment, I have to configure the scheduled event "releaseOldLocks", correct? Or isn't it necessary because this event is triggered by a Java-action?

Thanks in forward for the answer!


Hi Robert

The answer to your first question lies in the second question. If you enable the releaseOldLocks Scheduled Event, AND the 'enableReleaseLockEvent' constant is set to true, the locks should be released automatically if the browser window is closed in less then 10 minutes.

(Assuming that you work on mendix 2.5.3, but I guess it wont compile otherwise)