I have an entity called Lots as follows:
public class Lots implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int lotId;
@ManyToOne
private Boats boats;
private int numCrates;
....
And I also have an entity called Boats:
public class Boats implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int boatId;
@ManyToOne
private Users user;
private String name;
I am trying to create a named query on Lots as follows:
@NamedQueries({
@NamedQuery(name = "FindUsersByLot", query = "SELECT b FROM Lots b JOIN Boats a ON (b.boats.boatId = a.boatId) WHERE a.user = :user")
})
But this results in an EJB Exception.
How can I do a JOIN in a named query?