title: Why does validation not work on objects of type DTO, but only on entities
body: <p>I have an annotation set over objects of type <strong>dto</strong>, the same as over objects of type <strong>Entity</strong>. The annotation works on <strong>entities</strong>, but it does not work on objects of type <strong>dto</strong>.</p>
  
  <p>I work in <strong>SpringBoot</strong>.
  <strong>application.properties</strong></p>
  
  <pre><code>validate.packageid.size = "The field 'PACKAGEID' can contain only {max} symbols.";
  </code></pre>
  
  <p><strong>config file</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>@Configuration
  public class ServiceConfig implements WebMvcConfigurer {
  
      @Bean
      public MessageSource messageSource() {
          ResourceBundleMessageSource source = new ResourceBundleMessageSource();
          source.setDefaultEncoding("UTF-8");
          source.setBasename("classpath:ValidationMessages");
          return source;
      }
  
      @Nullable
      @Override
      public Validator getValidator() {
          LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
          validator.setValidationMessageSource(messageSource());
          return validator;
      }
  
  }
  </code></pre>
  
  <p><strong>dto</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>@Size(message = "{validate.packageid.size}", max = 36)
  private String documentId
  </code></pre>
  
  <p><strong>entity</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>@Column(name = "DOCUMENTID")
  @Size(message = "{validate.packageid.size}", max = 36)
  private String documentId;
  </code></pre>
  
  <p>I cannot use the annotation <strong>@Valid</strong> because I fill an object of <strong>dto</strong> type with reflection technology.</p>
  
  <pre class="lang-java prettyprint-override"><code>public static  &lt;S&gt; S fillData (S object, List&lt;Object&gt; values){
      return obtainMetadataOfObject(object, values);
  }
  </code></pre>
  
  <p>I need to be able to get the constraint annotation, or rather its parameters, set on the fields of the dto object (but in the case of the dto object I get null, since Spring may not know what to use the constraint annotations set on the fields of the dto object), in the case of entity - it turns out, but the entity validator is engaged by Spritg, since it manages the entity as a component from the Application context.</p>
  
  <p>To validate the dto on the web client side, I use the <strong>@Valid</strong> annotation in the parameters of the method that handles the request from the client</p>
  
  <p>For validation dto from </p>
  
  <p><strong>Update</strong></p>
  
  <p>I put the annotation <strong>@Validation</strong> over <strong>dto</strong> and after that I got the data I need.</p>
  
  <p>It work for classes that don't have classes-heir.</p>
  
  <p>I get data of annotation <strong>@Size</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>    private static int getMaxLimitSize(Field field){
  
              field.setAccessible(true);
  
              Size annotation = field.getAnnotation(Size.class);
  
              int zero = 0;
  
              if(annotation == null) return zero;
  
              return annotation.max();
  
          }
  </code></pre>
  
  <p>But this <strong>does not work</strong> for objects whose fields are split into several classes : several abstract and one produce.</p>
  
  <p>Validation does not work for composite objects of type <strong>DTO</strong>, Any help is appreciated?</p>