Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect SQL generated for @IdClass with fetch() on ToMany path #2317

Closed
rbygrave opened this issue Aug 16, 2021 · 0 comments
Closed

Incorrect SQL generated for @IdClass with fetch() on ToMany path #2317

rbygrave opened this issue Aug 16, 2021 · 0 comments
Assignees
Labels
Milestone

Comments

@rbygrave
Copy link
Member

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.name,
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant