[hibernate-issues] [JIRA] (BVAL-750) Is @Valid supported in composite constraints

user (JIRA) jira at hibernate.atlassian.net
Fri Jun 5 17:14:20 EDT 2020


user ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5edaad53f2f6dd0a9b0b6b35 ) *created* an issue

Bean Validation ( https://hibernate.atlassian.net/browse/BVAL?atlOrigin=eyJpIjoiYzAyOGIwMTBkNzQ3NDcxNWI5ZTc3YWE4ZDZmYzczNzQiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/BVAL-750?atlOrigin=eyJpIjoiYzAyOGIwMTBkNzQ3NDcxNWI5ZTc3YWE4ZDZmYzczNzQiLCJwIjoiaiJ9 ) BVAL-750 ( https://hibernate.atlassian.net/browse/BVAL-750?atlOrigin=eyJpIjoiYzAyOGIwMTBkNzQ3NDcxNWI5ZTc3YWE4ZDZmYzczNzQiLCJwIjoiaiJ9 ) Is @Valid supported in composite constraints ( https://hibernate.atlassian.net/browse/BVAL-750?atlOrigin=eyJpIjoiYzAyOGIwMTBkNzQ3NDcxNWI5ZTc3YWE4ZDZmYzczNzQiLCJwIjoiaiJ9 )

Issue Type: Bug Affects Versions: 2.0.2 Assignee: Unassigned Components: api, spec-general Created: 05/Jun/2020 14:14 PM Environment: OpenJDK 14
Hibernate Validator 6.1.4.Final
SE environment Labels: validation Priority: Minor Reporter: user ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5edaad53f2f6dd0a9b0b6b35 )

I have been trying to get @Valid to work in a composite constraint but no luck so far. I went through HV documentation and searched online to find out if @Valid is not supported in composite constraints but I can't find any mention of that.

Here is a simple example that shows the issue:

public class Foo {

  @NotNull                      // without composite constraint. both work as expected
  @Valid                          
  Bar bar

  @NotNullAndValid           // composite constraint consisting of @NotNull and @Valid
  Baz baz;                           // @NotNull gets applied but cascade validation (@Valid) does not

}

@NotNull
@Valid
@Constraint(validatedBy={})

// RUNTIME retention, FIELD target for simplicity

public @ interface NotNullAndValid {

  // message, groups, payload

}

So my question is this: Is @Valid supported in composite constraint? If not, can you please point me to some online resource that explains why.

My guess is that it's not supported for the following reason: @Valid does not support groups (i.e., if you have @Valid declared somewhere then cascade validation will always take place regardless of the validation group that was specified in/passed to the validator API call). On the other hand, composite constraints support groups/can be turned on/off by validating a bean for a specific group. If @Valid were to be placed in a composite constraint then you effectively make @Valid support groups (i.e., cascade validation will become group based rather than the mere presence/absence of @Valid constraint).

Any thoughts?

( https://hibernate.atlassian.net/browse/BVAL-750#add-comment?atlOrigin=eyJpIjoiYzAyOGIwMTBkNzQ3NDcxNWI5ZTc3YWE4ZDZmYzczNzQiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/BVAL-750#add-comment?atlOrigin=eyJpIjoiYzAyOGIwMTBkNzQ3NDcxNWI5ZTc3YWE4ZDZmYzczNzQiLCJwIjoiaiJ9 )

Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100128- sha1:078e4e4 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200605/fd213388/attachment.html 


More information about the hibernate-issues mailing list