title: Hibernate: @UniqueConstraint Across Multiple Tables?
body: <p>I have a data model in which a number of entities inherit some common attributes from a single superclass entity.  I am using <code>InheritanceType.JOINED</code> on the superclass, which causes Hibernate to create a single table for attributes defined in the superclass, with subclass tables containing only columns that are added by the subclass (so to load the attributes for a subclass instance, a join is performed between the two tables).  That is all working fine.</p>
  
  <p>What I'd like to do, however, is specify a unique constraint that includes fields in both the subclass and superclass tables.  For instance, say that my superclass entity is something like:</p>
  
  <pre><code>Thing: {id, name}
  </code></pre>
  
  <p>...and then I have some subclass entities like:</p>
  
  <pre><code>Company: {address}  //inherits 'id' and 'name' from 'Thing'
  Employee: {company} //inherits 'id' and 'name' from 'Thing'
  </code></pre>
  
  <p>...and I want to configure Hibernate to automatically enforce that a given <code>Company</code> cannot have two <code>Employee</code>'s with the same name.  The <code>company</code> field is in the <code>Employee</code> table, but the <code>name</code> field is in the <code>Thing</code> table, so is there any way to get Hibernate to enforce this constraint, or do I need to do it programmatically whenever I add a new <code>Employee</code>? </p>