We're updating the issue view to help you get more done. 

Investigate approach for a special group identifying contraints otherwise unassigned to a group.

Description

In https://hibernate.atlassian.net/browse/BVAL-638 I had a discussion with Gunnar Morling regarding a requirement to be able to specify a particular group when performing validation that selects contraints that are not explcitly assigned to a group.

This is to allow for relaxing constraints is specific circumstances while having default evaluation execute all constraints by default.

For example:

In the class

1 2 3 4 5 6 7 8 9 10 11 public class A { @NotNull public String a1; @NotNull public String a2; } I would like a way to express that by default all constraints should be validated but in particular validation points only a subset of these constraints be validated. I want to be able to do this by adjusting the annotation only on those constraints that are to be relaxed. As suggested by Gunnar, one approach is to introduce some ALL_UNASSIGNED pre-defined group then have the following, for example, if I want to be able to relax the constraint on a2.

public interface Complete extends Default {};

@GroupSequence({Complete.class, A.class})
public class A {
@NotNull
public String a1;

@NotNull(groups={Complete.class})
public String a2;
}

1 2 3 In this case, default validation will enforce the constraints on a1 and a2 but evaluation against ALL_UNASSIGNED would only evaluate the constraint on a1. It would also be useful to be able to specify specific constraints that are only evaluated in the relaxed case for example:

public interface Complete extends Default {};
public interface Partial extends {};

@GroupSequence({Complete.class, A.class})
public class A {
@NotNull
public String a1;

@NotNull(groups={Complete.class})
public String a2;

@NotNull(groups={Complete.class})
@Null(groups={Partial.class}})
public String a3
}

1 when validation this as:

validator.validate(instanceOfA, Partial.class, ALL_UNASSIGNED)

1

then the @Null constraint on a3 would be enforced but not otherwise. I think that would just work in the presence of an ALL_UNASSIGNED special validation group.

Environment

JDK 1.8.121

Status

Assignee

Unassigned

Reporter

Tim Bartley

Labels

None

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Affects versions

5.4.1.Final

Priority

Minor