0

I've written a query that works good if used into MySql Workbench, but it won't compile if used in my Java EE project!

Here's the query :

@NamedQuery(name = "Book.findByCourse", query = "SELECT b FROM Book b WHERE b.teaching IN (SELECT T.id FROM Teaching T, Course C WHERE T.course = C.id AND C.id = :course)")

The query works fine, but I've got this error in my Java EE project :

Error compiling the query [...], line 0, column 0: invalid IN expression argument [SubqueryNode Left: null Right: null], expected argument of type [entity.Teaching].

What's wrong with it?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
StepTNT
  • 3,867
  • 7
  • 41
  • 82

1 Answers1

0

First of all you are trying to select ids only in your subquery and then compare it to full pojo object (not sure if that's possible at all)

In my opinion you should either got with native query (@NamedNativeQuery) to achieve what you want or use Criteria Builder like for example here

Community
  • 1
  • 1
Kris
  • 5,714
  • 2
  • 27
  • 47