title: How to use different validation rules on same entity in Hibernate?
body: <p>Problem:
  How to save object Account as nested object when only ID is needed without getting ConstraintValidator exception?</p>
  
  <p>Problem is because i have set validation rules to class, but when i want to save sem entity as nested object i get exception that some property values are missing. So i would liek to have different validation rules when i want to persist object as a whole and when i want to use it only sa nested object (when only ID is needed).</p>
  
  <pre><code>public class Account {  
      private int id;
  
      @NotNull
      private String name;
  
      @NotNull
      private String lastName;
  
      @NotNull
      private String userName;
      //getters&amp;setters
  </code></pre>
  
  <p>If I include Account as nested object i just need ID to be able to use it as FK (account entity is already in DB), but because of @NotNull annotation i get Exception.</p>
  
  <p>Is there a way to ignore those annotations from Account when trying to save object Shop or how to create different validation rules for Account to validate just soem other properties and not all?</p>
  
  <pre><code>public class Shop { 
      private int id;
  
      private Account owner; // only ID is needed
  </code></pre>
  
  <p>Do you have any basic example? I dont understand those in documentation. I have already read documentation before posting here. </p>