title: Using wrapper Integer class or int primitive in hibernate mapping
body: <p>In the company that I work for we have this major discussion on whether it should be better to use wrapping classes for primitives (java.lang.Integer, java.lang.Long) or whether to use the primitive types directly in the POJOs that map Entities to Tables in Hibernate.</p>
  
  <p>The idea is that we want these values to not be null in the database.</p>
  
  <p><strong>The arguments in favor of using primitives:</strong></p>
  
  <ul>
  <li>Handling these values as int means that they can never be null, in
  this way making it impossible to inadvertently get a null reference
  on the field. </li>
  <li>int=32/64 bits of memory.  Integer = 16 bytes of memory
  and is also slower</li>
  </ul>
  
  <p><strong>The arguments in favor of using wrapper objects:</strong></p>
  
  <ul>
  <li>We can add a constraint at the database level to always prevent null
  values from getting there </li>
  <li>We can end up with misleading data, we can
  have 0's instead of nulls in the database whenever the user doesn't
  set a value and buggy data is a tough catch. </li>
  <li>Objects have more expressive power than primitives.  We have null values and also
  integer values, so we can validate them easier using  annotations for
  example (javax.validation.constraints.NotNull).</li>
  </ul>