The JPA finder for play 2 works with joins as well.
Imagine you have a Task model with a creator:
1 2 3 4 5 | @Entity(name = "tasks") public class Task extends Model { @ManyToOne public User creator; } |
referenced to a User model with a name:
1 2 3 4 | @Entity(name = "users") public class User extends Model< User> { public String name; } |
You can write a method to get all Task for a creator username by joining on creator and access the user fields with the creator.field syntax:
1 2 3 | public static List< Task> findByCreatorName(String creatorName){ return Task.query().join("creator").eq("creator.name", creatorName).findList(); } |
The source code for this example with unit tests is pushed to Play4Jpa
Information about Data protection