title: How can I skip bean validation if all fields for the entity are empty?
body: <p>I have a address entity like this:</p>
  
  <pre><code>@Entity
  public class Address implements java.io.Serializable {
      @Id @GeneratedValue(strategy = IDENTITY)
      private Long id;
  
      @Size(max = 100)
      private String street;
  
      @Size(max = 15)
      private String nr;
  
      @Field
      @Size(min = 1, max = 20) @NotBlank
      private String city;
  }
  </code></pre>
  
  <p>This is part of several other entities. For one such entity the address is optional.
  I have a view where our users can edit the whole entity via several form inputs, including several address fields.</p>
  
  <p>To be able to edit the address, I initialize the parent entity with an empty address entity.</p>
  
  <p>Now the problem is: I don't want to persist an <code>Address</code> on the entity when all address fields are empty. For that to work, I need to skip validation for the entity if (and only if) all fields of <code>Address</code> are empty. How do I do that in the most elegant way?</p>
  
  <p>What I'm currently doing is to skip bean validation altogether with <code>&lt;o:validateBean disabled="true" /&gt;</code> for the submit button, setting the address to <code>null</code> if it comes out empty. But this sounds like a total hack as it disables <em>all</em> validation in <em>all</em> cases. How can I do better?</p>