2012-08-23 14 views
8

Ich bin verwirrt von der javax.validation API. Ich schreibe einen einfachen Test zu verstehen:Wie konstruiere ich eine ConstraintViolationException?

Sample sample = new Sample(); 
Set<ConstraintViolation<Sample>> violations = validator.validate(sample); 
if (!violations.isEmpty()) { 
    // Eclipse refuses to let me use my violations variable 
    throw new ConstraintViolationException(violations); 
} 

Wie soll ich den Satz von Verletzungen erklären, damit ich es in meiner Ausnahme Konstruktor verwenden kann?

Antwort

10

Sie können wie so dieses Problem umgehen:

throw new ConstraintViolationException(
    new HashSet<ConstraintViolation<?>>(violations)); 

Sie interessiert sein BVAL-198 bei der Verfolgung, die dieses Problem behebt.

+1

Der Konstruktor wurde ab Bean Validation 1.1 behoben. – Gunnar

Verwandte Themen