title: JPA 2.0 unique constraint as XML
body: <p>I'm using JPA 2.0 and want to create a unique constraint using XML, not annotations.</p>
  
  <p>The annotated class looks like this:</p>
  
  <pre><code>@Entity
  public class Person {
      @Id
      @GeneratedValue
      private Long id;
      @Column(unique=true)
      private String name;
  
      // ..
  }
  </code></pre>
  
  <p>And the <code>orm.xml</code> file like that - it's missing the unique constraint though:</p>
  
  <pre><code>&lt;entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
      version="2.0"&gt;
      &lt;entity class="kiosk.model.Person"&gt;
          &lt;attributes&gt;
              &lt;id name="id"&gt;
                  &lt;generated-value strategy="AUTO" /&gt;
              &lt;/id&gt;
              &lt;basic name="name" /&gt;
  
              &lt;!-- .. --&gt;
          &lt;/attributes&gt;
      &lt;/entity&gt;
  &lt;/entity-mappings&gt;
  </code></pre>
  
  <p><strong>How do I add a unique constraint to a JPA 2.0 class using XML?</strong></p>