title: Composite key join in Hibernate with JPA
body: <p>I'm having a bit of trouble trying to solve this problem, but have struck out this far both in Java and on Google.</p>
  
  <p>I have two tables I want to join. They both have composite primary keys, and the child table has the same columns in the parent's PK, plus two additional ones. In Java, the classes look roughly (ignoring getters/setters, etc.) like this:</p>
  
  <pre><code>@Embeddable
  public class ParentKey {
      private Date someDate;
      private String someKeyField;
  }
  
  @Embeddable
  public class ChildKey {
      private Date someDate;
      private String someKeyField;
      private String anotherKeyField;
  }
  </code></pre>
  
  <p>I'm trying to query the Parent based on a <code>java.util.Date</code> and a <code>String</code>. Ideally, that eagerly fetched a <code>Set&lt;Child&gt;</code> joining on <code>someDate</code> and <code>someKeyField</code>.</p>
  
  <p>I've gotten it to the point where it's able to fetch the data for the parent just fine, but then it bombs with <code>ORA-01858: a non-numeric character was found where a numeric was expected</code> when fetching the children. I assume it has <em>something</em> to do with the <code>java.util.Date</code> field, but I'm not really sure what.</p>
  
  <p>The two entity classes look something like this:</p>
  
  <pre><code>@Entity
  public class Parent {
  
      @EmbeddedId
      private ParentKey key;
  
      @OneToMany(fetch = EAGER, mappedBy = "parent")
      private Set&lt;Child&gt; children;
  
      private String someData;
      // more data
  }
  
  @Entity
  public class Child {
  
      @EmbeddedId
      private ChildKey key;
  
      @ManyToOne
      @JoinColumn({
          @JoinColumn(name = "SOME_DATE", insertable = false, updatable = false),
          @JoinColumn(name = "SOME_KEY_FIELD", insertable = false, updatable = false),
      })
      private Parent parent;
  
      private String someChildData;
      // more data
  }
  </code></pre>
  
  <p>Both the parent and child tables have the "SOME_DATE" (date type) and "SOME_KEY_FIELD" (vachar2 type) columns in them. I can see Hibernate attempting the second query when I print the queries, so it found some parents and is trying to look for children.</p>
  
  <p>I probably did something erroneous above, but I can't imagine anything I did that would cause <code>ORA-01858</code>. Even if I remove all the additional fields and stick purely to the key fields, I get the same error, so I feel Hibernate's doing something unexpected, I just don't know what.</p>
  
  <p>Is there a better way of doing such a join or organizing my <code>@EmbeddedIds</code>? Is there something glaringly wrong with what I'm doing?</p>
  
  <p>Edit: I've printed out the bind variables of the query for children and it's binding in the wrong order. I think if there's a way to specify the fields from the parent and which column they bind to, this will be solved.</p>