Jmix Studio enforces invalid constraint property name

Jmix version: 1.3.1
Jmix Studio plugin version: 1.3.3-213
IntelliJ IDEA 2022.1.4 (Community Edition)
Build #IC-221.6008.13, built on July 19, 2022
Runtime version: 11.0.15+10-b2043.56 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Kotlin: 221-1.7.10-release-333-IJ5591.52
Java Version: java 17.0.4 2022-07-19 LTS
Java™ SE Runtime Environment (build 17.0.4+11-LTS-179)
Java HotSpot™ 64-Bit Server VM (build 17.0.4+11-LTS-179, mixed mode, sharing)
Operating System: macOS 12.4 (21F79)
File System: Case-Sensitive Journaled HFS+ (APFS)
Datebase: PostgreSQL 13

Hello Everyone

For your information, I have the following problem with Jmix Studio.

In the “Handling Unique Constraint Violation Exceptions” documentation

https://docs.jmix.io/jmix/ui/exception-handlers/unique-constraint-violation-exception.html

it says that I may choose a name for my DB constraints and that it should be prefixed with databaseUniqueConstraintViolation.

However, when I try to enter my own name in the Studio “Indexes” view, e.g. for my User entity, Studio enforces a name of the form IDX_xyz_USER_UNQ and only allows me to append text to this. So for example, I may write IDX_NF_USER_UNQ_USERNAME but cannot modify the text before “_USERNAME”.

@JmixEntity
@Entity(name = “sec$User”)
@Table(name = “SEC_USER”, indexes = {
@Index(name = “IDX_NF_USER_UNQ_USERNAME”, columnList = “USERNAME”, unique = true)
}, uniqueConstraints = {
@UniqueConstraint(name = “IDX_NF_USER_UNQ_EMAIL”, columnNames = {“EMAIL”})
})
public class User implements JmixUserDetails, HasTimeZone {

But at runtime Jmix wants the following property:

databaseUniqueConstraintViolation.IDX_SEC_USER_ON_USERNAME

If I have the following in my messages_en.properties file:

databaseUniqueConstraintViolation.IDX_NF_USER_UNQ_USERNAME=ERROR: A user with the same username already exists

then I receive the following message at runtime:

Unique constraint violation occurred (IDX_SEC_USER_ON_USERNAME)

I have modified my naming as a temporary workaround to receive my message but can you please correct this. Thanks in advance for your support.

Best regards
Chris

Looks like your database still contains the index named IDX_SEC_USER_ON_USERNAME. That’s why you see the desired message only if you add databaseUniqueConstraintViolation.IDX_SEC_USER_ON_USERNAME to the message bundle.

@krivopustov
Hello Konstantin

Thank you for the feedback and your support. Yes, you are correct; there was in index still in the database, however, I cannot explain this. I removed that index and replaced it with the new one in Studio to keep its naming in line with the new email constraint that I added and I recreated the database after that. (At least I selected that action.) And before I created this forum topic I did a “Find in Files” in Studio and the IDX_SEC_USER_ON_USERNAME index was not anywhere in the Liquibase change logs. That’s also why I did not look at the database itself; I was relying on the change log information. But now when I think about it, I should have at least seen the original create in the logs but there was nothing. And after I removed/replaced it, I should have found a drop instruction but there was really nothing.

I can only assume that the “Find in Files” was not working correctly but that would also be strange. I did have a problem where I could not build my project after opening a separate one and I resolved it by invalidating the caches and restarting. Unfortunately, I cannot exactly remember when it occurred, so I do know if it had any affect on the behaviour I have described here.

I will try and reproduce this situation because I am convinced that something was not synchronized correctly.

Best regards
Chris