I have 3 tables with the following structure.
User
uid
username
password
Friend
id
uid
fid
Post
pid
uid
msg
I want to find all the posts that the friends of a user did. In SQL I extract that using this statement:
SELECT post.* FROM Post
INNER JOIN Friend f ON f.fid = post.uid
INNER JOIN User u ON f.uid = u.uid
WHERE u.uid = 1;
How can I convert this to JPQL?
JPQL queries entities and their associations, and you haven’t described them, so it’s a bit hard to say. But assuming a Post has a ManyToOne with a Friend, and a Friend has a ManyToMany with a User, the query would be: