I could do this easily enough in native MySQL but I'm having real trouble getting my head around how JPA handles foreign-key references, and various other differences in syntax between SQL and the JPA query language.