title: JPA: Which should I use? Basic(optional) or Column(nullable)?
body: <p>For simple string field,</p>
  
  <pre><code>@Entity
  class Foo {
  
      //1. @Basic(optional = false)
      //2. @Column(length = 100, nullable = false)
      String name;
  }
  </code></pre>
  
  <p>I need to restrict name's length using <code>@Column</code> annotation, but I'm confused with the nullable attribute. While I'm using other annotations like <code>@ManyToOne</code> and <code>@OneToMany</code> those use <code>optional</code> attributes, I feel like to use <code>@Basic(optional)</code> to keep most annotations uniform. But I can't restrict the name's length with <code>@Basic</code>.</p>
  
  <p>So, where should I annotate the nullable attribute, by <code>@Basic</code> or <code>@Column</code>?</p>
  
  <p><em>EDIT</em></p>
  
  <p>Simply say, in which form would you prefer:</p>
  
  <p>Form 1:</p>
  
  <pre><code>@Entity
  class Foo {
      @Basic(optional = false)
      @Column(length = 100)
      String name;
  }
  </code></pre>
  
  <p>Form 2:</p>
  
  <pre><code>@Entity
  class Foo {
      @Column(length = 100, nullable = false)
      String name;
  }
  </code></pre>
  
  <p>Well personally I like Form 1, because <code>optional</code> attribute is also used by <code>@ManyToOne</code> etc. annotations, but Form 2 is also good because it's done in single annotation.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>After read <a href="http://markmail.org/message/osod6rsauwbnkvya" rel="noreferrer">http://markmail.org/message/osod6rsauwbnkvya</a>, I've got the difference between <code>@Basic.optional</code> and <code>@Column.nullable</code>. But I still don't know which one I should use. It seems like good to include both annotations, so make the underlying table well defined, and check null in JPA before the actual update maybe slightly faster.</p>