title: How to check if object have been saved to database
body: <p>I am using Spring JDBC and I want to create a method which checks if it have been persisted to the database yet or not, meaning that would have gotten an auto incremented key.</p>
  
  <p>I have a field named <code>id</code> of type int. Since primitive ints are auto assigned 0 if no other values is given I could create a method that checks if <code>id == 0</code> but then I must ensure that my primary key sequences starts on 1. </p>
  
  <p>I could also create a method in the repository to check if the object was saved, however I do not want to do a query for this. </p>
  
  <p>Last option that I could think of was to change the type of the <code>id</code> to <code>Integer</code> and then check if it was <code>null</code> but I don't know if that is a good way to do it.</p>
  
  <p>Are there a way to have a method in the domain layer to do this?</p>