I am able to use @IdClass to handle composite keys and it is working fairly well on a single entity class. However, when using query bean to eagerly fetch the related entities, I ran into an error "ORA-00911: invalid character". The use case contains two classes Parent and Child.
public class Parent {
@Id int key1;
@Id int key2;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumns({@JoinColumn(name="key1", referenceColumnName = "key1"), @JoinColumn(name="key2", referenceColumnName = "key2")})
List<Child> children;
}
public class Child {
@Id int key1;
@Id int key2;
@Id String name;
int age;
}
The idClass for Parent has fields key1 and key2. The idClass for Child has fields key1, key2, name.
When I try to execute
new QParent()
.key1.eq(123)
.fetch("children")
.findList();
I got the following error (after removing many other lines of the stacktrace). The query seemed to be correct except the order by phrase at the end "ORDER BY _idClass.key1 and _idClass.key2". The other old thing is that t0.key1 and t0.key2 appeared twice.
javax.persistence.PersistenceException: Query threw SQLException:ORA-00911: invalid character
Bind value:[123] Query was
SELECT
t0.key1,
t0.key2,
t0.key1,
t0.key2,
t1.key1,
t1.key2,
t1.age,
FROM
PARENT t0
LEFT JOIN CHILD t1
ON t1.key1 = t0.key1 AND t1.key1 = t0.key2
WHERE t0.key1 = ?
ORDER BY
_idClass.key1,
_idClass.key2
Caused by: Error : 911, Position : 749, sql = .... REPEATING THE QUERY ABOVE... , Error Msg = ORA-00911: invalid character
Thanks for your help.
Buck