2016-08-15 14 views
5

मुझे आश्चर्य है कि कैसे हाइबरनेट NullValidator वर्ग जो ConstraintValidator इंटरफ़ेस फैली भले ही @Null एनोटेशन परिभाषा इस प्रकार है पाता है:कैसे सत्यापित किया जाता है जब हाइबरनेट वैलिडेटेटर को रोकथाम वैधता मिलती है?

@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) 
@Retention(RUNTIME) 
@Documented 
@Constraint(validatedBy = { }) 
public @interface Null {} 

उत्तर

4

validatedBy केवल कस्टम के लिए निर्दिष्ट करने की आवश्यकता है (अर्थात उपयोगकर्ता-निर्मित) की कमी। हाइबरनेट को जाने वाली सभी अंतर्निहित बाधाओं को स्वचालित रूप से मैप किया जाता है। निम्नलिखित कोड है, जो ConstraintDescriptorImpl और XmlMappingParser में प्रकट होता है देखें:

if (constraintHelper.isBuiltinConstraint(annotationType)) { 
    constraintDefinitionClasses.addAll(constraintHelper.getBuiltInConstraints(annotationType)); 
} 
else { 
    Class<? extends ConstraintValidator<?, ?>>[] validatedBy = annotationType 
      .getAnnotation(Constraint.class) 
      .validatedBy(); 
    constraintDefinitionClasses.addAll(Arrays.asList(validatedBy)); 
} 

ConstraintHelper की एक सूची है सब में निर्मित की कमी, इन टिप्पणी प्रकार के लिए isBuiltinConstraint विधि से मिल जाएगा जो।

संबंधित मुद्दे