title: Java Validation: Validate an object within an object
body: <p>I have two objects:</p>
  
  <pre><code>public class CancelRequest{
   @NotEmpty
   private String id;
  
   @NotNull
   private BookingDetails;
  }
  </code></pre>
  
  <p>BookingDetails object:</p>
  
  <pre><code>public class BookingDetails{
   @NotEmpty
   private String bookingId;
  }
  </code></pre>
  
  <p>My class that is responsible for validating the request is <code>CancelRequestValidator</code></p>
  
  <pre><code>...
  import javax.validation.Validator;
  ...
  public class CancelRequestValidator{
  ...
  public void check(CancelRequest request){
   Set&lt;ConstraintViolation&lt;NorthAmericaCancelTripRequest&gt;&gt; violations = 
  validator.validate(request);
  ...
   }
  }
  </code></pre>
  
  <p>how I am performing validation?</p>
  
  <pre><code>CancelRequest request = new CancelRequest("id",new BookingDetails(""));
  CancelValidator validator = new CancelValidator();
  violations = validator.check(request);
  </code></pre>
  
  <p>The violation should have one entry in it saying bookingId cannot be empty but instead it thinks that the object valid. I need to do the validation this way because I have some other business validation that I need to perform on this object hence I am using a mixture of javax and custom validation. </p>
  
  <p>thanks</p>