title: JPA mapped model returns null elements with Composite-Keys
body: <p>I have build my data model using JPA and am using Hibernate's EntityManager 3 to access the data.  I used HSQLDB for testing (junit).  I am using this configuration for other classes and have had no problems.  </p>
  
  <p>However, the latest batch of tables use a composite-key as the primary-key and I am not able to retrieve the populated row from the database when it is implemented.  I don't get an error, the query simply returns null objects.</p>
  
  <p>For example if I query (using jsql) "FROM Order o" to return a list of all orders in the table, my list.size() has the proper number of elements (2), but the elements are null.</p>
  
  <p>I am hoping that someone with a sharper eye than I can discern what I am doing wrong.  Thanks in advance!</p>
  
  <p>The (simplified) tables are defined as:</p>
  
  <pre><code>CREATE TABLE member (
      member_id INTEGER NOT NULL IDENTITY PRIMARY KEY);
  
  CREATE TABLE orders (
      orders_id INTEGER NOT NULL,
      member_id INTEGER NOT NULL,
      PRIMARY KEY(orders_id, member_id));
  
  ALTER TABLE orders 
      ADD CONSTRAINT fk_orders_member 
      FOREIGN KEY (member_id) REFERENCES member(member_id);
  </code></pre>
  
  <p>The entity POJOs are defined by:</p>
  
  <pre><code>@Entity
  public class Member extends Person implements Model&lt;Integer&gt;{
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      @Column(name="MEMBER_ID", nullable=false)
      private Integer memberId;
  
      @OneToMany(fetch=FetchType.LAZY, mappedBy="member", cascade=CascadeType.ALL)
      private Set&lt;Order&gt; orderList;
  }
  
  @Entity
  @Table(name="ORDERS")
  @IdClass(OrderPK.class)
  public class Order extends GeneralTableInformation implements Model&lt;Integer&gt;{
  
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      @Column(name="ORDERS_ID", nullable=false)
      private Integer orderId;
  
      @Id
      @Column(name="MEMBER_ID", nullable=false)
      private Integer memberId;
  
      @ManyToOne(optional=false, fetch=FetchType.LAZY)
      @JoinColumn(name="MEMBER_ID", nullable=false)
      private Member member;
  
      @OneToMany(mappedBy="order", fetch=FetchType.LAZY)
      private Set&lt;Note&gt; noteList;
  }
  </code></pre>
  
  <p>OrderPK defines a default constructor and 2 properties (orderId, memberId) along with their get/set methods.</p>
  
  <pre><code>public class OrderPK implements Serializable {
  private static final long serialVersionUID = 1L;
  
  private Integer orderId;
  private Integer memberId;
  
  public OrderPK() {}
  
  public OrderPK(Integer orderId, Integer memberId) {
      this.orderId = orderId;
      this.memberId = memberId;
  }
  
  /**Getters/Setters**/
  
  @Override
  public int hashCode() {
      return orderId.hashCode() + memberId.hashCode(); 
  }
  
  @Override
  public boolean equals(Object obj) {
      if (this == obj) return true;
      if (obj == null) return false;
      if (!(obj instanceof OrderPK))
          return false;
  
      OrderPK other = (OrderPK) obj;
      if (memberId == null) {
          if (other.memberId != null) return false;
      } else if (!memberId.equals(other.memberId))
          return false;
      if (orderId == null) {
          if (other.orderId != null) return false;
      } else if (!orderId.equals(other.orderId))
          return false;
      return true;
  }   
  </code></pre>
  
  <p>}</p>
  
  <p>(sorry for the length)</p>
  
  <p>the entityManager is instantiated in an abstract class which is then extended by my other DAOs</p>
  
  <pre><code>protected EntityManager em;
  
  @PersistenceContext
  public void setEntityManager(EntityManager em) {
      this.em = em;
  }
  </code></pre>
  
  <p>and is configured by a spring context configuration file</p>
  
  <pre><code>&lt;bean id="entityManagerFactory" 
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
      p:dataSource-ref="dataSource" 
      p:jpaVendorAdapter-ref="jpaAdapter"&gt;
      &lt;property name="loadTimeWeaver"&gt;
          &lt;bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" /&gt;
      &lt;/property&gt;
      &lt;property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>My test class </p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration
  public class OrderDaoTest {
  
      @Autowired
      protected OrderDao dao = null;
  
      @Test
      public void findAllOrdersTest() {
      List&lt;Order&gt; ol = dao.findAll();
      assertNotNull(ol); //pass
          assertEquals(2, ol.size(); //pass
          for (Order o : ol) {
              assertNotNull(o); //fail
              ...
          } 
      }
  }
  </code></pre>
  
  <p>When I strip away the composite-key from the Order class I am able to retrieve data, I am not sure what I am doing incorrectly with my mapping or configuration.  Any help is greatly appreciated.</p>