Row level exception

1.5
I imported a json file to Row level role and experience this exception
image
I already had this message.properties

databaseUniqueConstraintViolation.SEC_ROW_LEVEL_POLICY_pkey

I also have an exception handler but none of these works.
Please advise,

Greetings,

Can you create steps to reproduce(or test project) this error, because when I trying to import existing role - this error not happening, it is just ok to import

Best regards,
Dmitry

Steps to reproduce:

  1. Access Row Role Level menu
  2. Export one row to JSON
  3. Open that JSON and remove an ID and save
    image
  4. Import that JSON

Expected Behavior: Our project custom message displayed (we have exception handler)
Actual Behavior: Full exception message displayed

1 Like

Finaly i reproduce it, but with workaround with random button with code

        RowLevelRoleEntity rowLevelRoleEntity = dataManager.create(RowLevelRoleEntity.class);
        rowLevelRoleEntity.setId(UUID.fromString("f9df270b-6321-4092-a872-0587557a7d71"));
        rowLevelRoleEntity.setCode("asd");
        rowLevelRoleEntity.setName("asd");
        dataManager.save(rowLevelRoleEntity);

Using jmix 1.5/1.5.5/1.6.2 and Postgres. Idk how do you reproduce it with cleaning id from Json, but for my case - no matter what empty id or duplicate - Json export and import just duplicates or ignoring(updating) existing row level role or create new with random uuid.

Anyway, the error “org.eclipse.persistence.exceptions.DatabaseException” seems like generic error and intercepted in jmix core before ours. I tested

@Order(JmixOrder.HIGHEST_PRECEDENCE)
@Component("uiex1_ZeroBalanceExceptionHandler")
public class EHP extends AbstractUiExceptionHandler {

    public EHP() {
        super("org.eclipse.persistence.exceptions.DatabaseException");
    }

    @Override
    protected void doHandle(String className, String message,
                            @Nullable Throwable throwable, UiContext context) {
        context.getNotifications().create(Notifications.NotificationType.ERROR)
                .withCaption("Error asdsadsa")
                .withDescription(message)
                .show();
    }
}

But somehow this doesnt work, i guess i need more research time.

About message handle. This is pretty funny case. E.g. you can try intercept unique user id with message
databaseUniqueConstraintViolation.USER__Pkey=asda but this also wont work, but after attempt to rename it to something like this “IDX_USER__ON_ID” → All work.

So to make you exception localized for unique values you need to write second part of key from SCREAMING_SNAKE_CASE.

solution

So, instead of SEC_ROW_LEVEL_ROLE_pkey use SEC_ROW_LEVEL_ROLE_PKEY

PS
If you need help with custom excpetion handling via custom class - mention me in this thread