[
https://issues.apache.org/jira/browse/BVAL-116?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Albert Lee resolved BVAL-116.
-----------------------------
Resolution: Fixed
> Multiple errors reported for a single validation failure with composite keys
> ----------------------------------------------------------------------------
>
> Key: BVAL-116
> URL: https://issues.apache.org/jira/browse/BVAL-116
> Project: BVal
> Issue Type: Bug
> Components: jsr303
> Affects Versions: 0.5
> Reporter: Joe Gamache
> Assignee: Albert Lee
> Fix For: 0.6, 0.4.1-incubating
>
> Attachments: BVAL-116.patch
>
>
> Am testing using JPA 2.0 and have an Entity with a composite key consisting
> of three columns. All are set to be "Not Null" in the database definition.
> When a test runs that has only one of the three values set to null, three
> error messages are returned. It was not too hard to figure out why. In the
> org.apache.bval.jsr303.ConstraintValidation, there is this code starting at
> around line 170:
> {code}
> // process composed constraints
> if (isReportAsSingleViolation()) {
> ConstraintValidationListener<?> listener = context.getListener();
> listener.beginReportAsSingle();
> boolean failed = listener.hasViolations();
> try {
> // stop validating when already failed and
> // ReportAsSingleInvalidConstraint = true ?
> for (Iterator<ConstraintValidation<?>> composed =
> getComposingValidations().iterator(); !failed && composed.hasNext();) {
> composed.next().validate(context);
> failed = listener.hasViolations();
> }
> } finally {
> listener.endReportAsSingle();
> // Restore current constraint validation
> context.setConstraintValidation(this);
> }
> if (failed) {
> // TODO RSt - how should the composed constraint error report
> look like?
> ConstraintValidatorContextImpl jsrContext = new
> ConstraintValidatorContextImpl(context, this);
> addErrors(context, jsrContext); // add defaultErrorMessage
> only
> return;
> }
> }
> {code}
> This same code gets executed all three times (as we have three components to
> the primary key). As "luck" would have it, for my first pass through the
> first one was the one with the NULL value. This set's the "hasViolations" in
> the "listener" object. Since they all pass in the same context, they pass in
> the same listener. Thus, even though the subsequent calls to
> "compose.next().validate(context)" do NOT fail, "failed" is still set to true…
> Fix this if you can, but I can't really generate a stand alone test case for
> you - I have deadlines too! It doesn't seem to hard to me though...
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira