First off, when you're asking why you get an exception, please post the stacktrace. However, I think the problem is that you're still thinking SQL
when you should be thinking JPQL
. Try this instead:
@NamedQuery(name = "FindUsersByLot", query = "SELECT b FROM Lots b JOIN b.boats a WHERE a.user = :user")
Explanation - you're assuming that each Lots
record will contain a boatId
column, which may or may not be the case. In @ManyToOne
the JPA provider will likely opt to storing the relationship on the Boats
side. As for why did I write the query the way I did, look into this.