Entity validation when using dataManager.commit

Hi,
In my entity I have this validation:

@Length(message = "{msg://ADDRESS_TOO_SHORT}", min = 10, max = 52)
@NotNull(message = "{msg://ADDRESS_MUST_BE_SET}")
@Column(name = "ADDRESS1")
protected String address1;

when saving with dataManager.commit Im able to save nulls in address1. but from the cuba app UI im not.

I also added @Validated to the service method. the programatic validation works via beanValidation.getValidator.

  1. How can I enable entity validation from the rest service?
  2. is this conversion ok? msg://ADDRESS_MUST_BE_SET, or there is a standard for that

Thanks

Hi,
are you talking about the problem discussed in this topic? If no, please provide a demo project where I can see how you invoke services and to reproduce the problem, because I don’t fully understand your case.

As or the 2, can you please explain what do you mean? A standard for what are you looking for?

Hi @gorbunkov .
Took me some time, but I have now an example.
I have added NewEntity with string field name. the field has some validations:
image

if you run the test in SampleIntegrationTest.testLoadUser, the test will run successfully. even though it is violating the validations. so the expected result should be exception.

if you run the app in the browser, it will not be saved with null or value < 5 .

How can I force the dataManager to run data valudation. why only the UI run the validation and dataManager dont.

Thanks

ServiceProblem.zip (9.5 MB)

Got it now. DataManager should not perform validation by design. All cases when validation is performed automatically is described in the documentation. If you need to validate the entity before it is commited, validate it explicitly.

I think its an anti pattern… :thinking:

This gives you a flexibility. There are cases when you need to save an entity even some validation rules are violated. If you need to check validation rules before saving, just call these checks explicitly.

I think it should be the other way around, if you dont want to validate, you need to force that expicitly…

I think we should enforce the rules by default and just give a project-level toggle for backward compatibility. Created issue.

Cool. I think you should link this post because it has so,e details about the need…

Done. Thanks for reminding!