title: HSQLDB not properly recognizing Primary Key from JPA Annotations
body: <p>We use Oracle for our production Database and HSQLDB for our Unit Test Database.  Both environments use Hibernate as the JPA provider.  The following code works properly in production, but throws <code>SQL Error: -104, SQLState: 23505 - integrity constraint violation: unique constraint or index violation</code> when run under jUnit.  The Entities in question are:</p>
  
  <pre><code>@Entity
  @Table(name="TT_TEACHERSECTIONGROUP")
  public class TeacherSectionGroup implements TeacherSectionListItem {
    @Id
    @Column(name="TEACHERSECTIONGROUPID",unique=true,nullable=false)
    @GeneratedValue(strategy=GenerationType.AUTO,generator="TT_TEACHERSECTIONGROUPID_SEQUENCE")
    @SequenceGenerator(name="TT_TEACHERSECTIONGROUPID_SEQUENCE",sequenceName="TT_TEACHERSECTIONGROUP_SQ")
    private Long id;
      .
      .
      .
    @OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.DETACH)
    @JoinTable(name="TT_TEACHERSECTIONGROUPASSOC",joinColumns={
      @JoinColumn(name="TEACHERSECTIONGROUPID",referencedColumnName="TEACHERSECTIONGROUPID")
    },inverseJoinColumns={
      @JoinColumn(name="USERSDCID",referencedColumnName="USERSDCID"),
      @JoinColumn(name="SECTIONSDCID",referencedColumnName="SECTIONSDCID")
    })
    private List&lt;TeacherSection&gt; sections;
      .
      .
      .
  </code></pre>
  
  <p>And the other end of the join:</p>
  
  <pre><code>@Entity
  @Table(name="TT_TEACHERSECTION")
  public class TeacherSection implements TeacherSectionListItem {
    @EmbeddedId
    private TeacherSectionPK key;
      .
      .
      .
  </code></pre>
  
  <p>With the Primary Key class:</p>
  
  <pre><code>@Embeddable
  public class TeacherSectionPK implements Serializable {
    @Column(name="SECTIONSDCID",nullable=false)
    private Long sectionId;
  
    @Column(name="USERSDCID",nullable=false)
    private Long usersDcid;
      .
      .
      .
  </code></pre>
  
  <p>The (cleaned up) output in the logs contains these hibernate statements that are being issued:</p>
  
  <pre><code>DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTION (DISPLAYNAME, POSITION, SECTIONSDCID, USERSDCID) values (&lt;null&gt;, &lt;null&gt;, 13820, 1)
  DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTION (DISPLAYNAME, POSITION, SECTIONSDCID, USERSDCID) values (&lt;null&gt;, &lt;null&gt;, 13821, 1)
  DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTION (DISPLAYNAME, POSITION, SECTIONSDCID, USERSDCID) values (&lt;null&gt;, &lt;null&gt;, 13957, 1)
  DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTION (DISPLAYNAME, POSITION, SECTIONSDCID, USERSDCID) values (&lt;null&gt;, &lt;null&gt;, 13958, 1)
  DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTION (DISPLAYNAME, POSITION, SECTIONSDCID, USERSDCID) values (&lt;null&gt;, &lt;null&gt;, 14234, 1)
  DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTION (DISPLAYNAME, POSITION, SECTIONSDCID, USERSDCID) values (&lt;null&gt;, &lt;null&gt;, 14235, 1)
  DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTIONGROUP (TEACHERSECTIONGROUPID, DISPLAYNAME, EXPRESSION, ISMODIFIED, NAME, POSITION, USERSDCID) values (default, &lt;null&gt;, 'Course(91642)', false, 'AP Chemistry', 0, 1)
  DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTIONGROUP (TEACHERSECTIONGROUPID, DISPLAYNAME, EXPRESSION, ISMODIFIED, NAME, POSITION, USERSDCID) values (default, &lt;null&gt;, 'Course(723)', false, 'Gen Chemistry', 1, 1)
  DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTIONGROUP (TEACHERSECTIONGROUPID, DISPLAYNAME, EXPRESSION, ISMODIFIED, NAME, POSITION, USERSDCID) values (default, &lt;null&gt;, 'Expression(3(A-B))', false, '3(A-B)', 2, 1)
  DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTIONGROUPASSOC (TEACHERSECTIONGROUPID, SECTIONSDCID, USERSDCID) values (1, 13820, 1)
  DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTIONGROUPASSOC (TEACHERSECTIONGROUPID, SECTIONSDCID, USERSDCID) values (1, 13821, 1)
  DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTIONGROUPASSOC (TEACHERSECTIONGROUPID, SECTIONSDCID, USERSDCID) values (2, 13957, 1)
  DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTIONGROUPASSOC (TEACHERSECTIONGROUPID, SECTIONSDCID, USERSDCID) values (2, 13958, 1)
  DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTIONGROUPASSOC (TEACHERSECTIONGROUPID, SECTIONSDCID, USERSDCID) values (2, 14234, 1)
  DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTIONGROUPASSOC (TEACHERSECTIONGROUPID, SECTIONSDCID, USERSDCID) values (2, 14235, 1)
  DEBUG org.hibernate.SQL  - insert into TT_TEACHERSECTIONGROUPASSOC (TEACHERSECTIONGROUPID, SECTIONSDCID, USERSDCID) values (3, 13957, 1)
  WARN  org.hibernate.engine.jdbc.spi.SqlExceptionHelper  - SQL Error: -104, SQLState: 23505
  ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper  - integrity constraint violation: unique constraint or index violation; SYS_CT_10323 table: TT_TEACHERSECTIONGROUPASSOC
  </code></pre>
  
  <p>It appears that HSQLDB is only using the Inverse Join Columns as the Primary Key for the JoinTable instead of all of the columns, as would make sense (and as I've seen documented around the inter-tubes)</p>
  
  <p>Is there a mechanism that I'm missing to specify to HSQLDB which fields should be included in the Primary Key?  Since this code actually works correctly in Oracle (i.e. production), I'm loath to rewrite it just to satisfy a unit test so I'm hoping there's an answer that will work equally well in either environment.  Thanks.</p>