I have an entity say User with an attribute say group which has @NotNull constraint.
I am deriving and setting this group in UserEntityListener in method beforeInsert. This works when I create an user from UI (form does not have group field) but throws error that ‘group is required’ when I create using v2 API and do not pass group as it is supposed to be inserted by listener before actually saving to db.
By design, there is a difference between validation in the generic REST-API and UI layer. REST-API validates all the data before sending it to the middleware, because there is no way to change the generic REST-API methods.
If you always set group in the entity listener, probably, there is no need to use BeanValidation, just use required attribute in UI if it is required in some use cases.
Please note, that BeanValidation is not used in middleware layer, it is a mechanism of client layers: web / rest-api.