Reputation: 1379
I'm having a bit of trouble trying to solve this problem, but have struck out this far both in Java and on Google.
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:
@Embeddable
public class ParentKey {
private Date someDate;
private String someKeyField;
}
@Embeddable
public class ChildKey {
private Date someDate;
private String someKeyField;
private String anotherKeyField;
}
I'm trying to query the Parent based on a java.util.Date
and a String
. Ideally, that eagerly fetched a Set<Child>
joining on someDate
and someKeyField
.
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 ORA-01858: a non-numeric character was found where a numeric was expected
when fetching the children. I assume it has something to do with the java.util.Date
field, but I'm not really sure what.
The two entity classes look something like this:
@Entity
public class Parent {
@EmbeddedId
private ParentKey key;
@OneToMany(fetch = EAGER, mappedBy = "parent")
private Set<Child> 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
}
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.
I probably did something erroneous above, but I can't imagine anything I did that would cause ORA-01858
. 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.
Is there a better way of doing such a join or organizing my @EmbeddedIds
? Is there something glaringly wrong with what I'm doing?
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.
Upvotes: 1
Views: 1244
Reputation: 1379
After looking at the Hibernate debug showing the bind variables, it was clear it wasn't binding the right parameters in the child query (that Hibernate generates). It seemed a bit random.
Adding referencedColumnNames
to the @JoinColumn
annotations fixed it, though.
Upvotes: 1