Mendix incorrectly detects unique constraint violation.

0
I have an entity (CT_Overview) which is supposed to have 1 field that is unique – this entity, as shown below, has several associations, but all of those associations points to only 1 of the given entity. I have checked that the existing list of this type of entity has unique values for the attributes on which I apply this unique attribute constraint.   Here is the list of objects of type CT_Overview:   Here is the only validation rule set up for the domain model in the first screenshot, as applied to the CT_Overview entity:   What is it that makes Mendix assume that the CaseNr attribute isn’t unique despite my data grid showing that it is?
asked
3 answers
1

Hello Andreas,

I would check that you’re not attempting to create two objects at the same time. It would be useful to see some of your flows.

I would also suggest checking your DB at the time of the commit – you can do this by sticking a break point and directly looking into the DB on a local machine, or you can try to do a retrieve from DB for a match in case you’re running this on a server.

On a side note, I suggest not adding CaseNr as an attribute on CT_Item, if you need to show the CaseNr you can always do it via association, there is no need to duplicate attributes from CT_Overview to CT_Item.

Hope this helps 

answered
1

CaseNr on the CT_Overview entity must be unique, this is checked by Mendix on database level.

CaseNr on the CT_Item has no unique constraint enabled

answered
0

Follow-up:
After trying the suggestions from the replies to this thread, I have settled with the approach of performing validations in the microflow that saves the object - this is partly because using a Before Commit event did not stop the object from being committed if the BCO microflow returned false, and partly because all changes made to the CT_Overview entity already has a microflow for validating that all fields are filled out properly.

answered