ellou 'kalvish
Relationships between models establish common JPA annotations such as @OneToMany , @ManyToOne , @OneToOne , etc.
So, if you have a User.java model for a user table and a Question.java model for a Question user, you can join it using @OneToMany (One User has many Question s)
User
@Entity public class User extends Model { @Id public Long id; public String email; @OneToMany public List<Question> questions; }
Question
@Entity public class Question extends Model { @Id public Long id; public String question; }
When you select a user in the controller, Ebean will default to “connections” and also select all user questions:
User user = User.find.where().eq("email", email).findUnique(); List<Question> usersQuestion = user.questions;
By default, Ebean retrieves all the properties and relationships of objects, so you don't need to create subqueries. Of course, you can or should even select / select only the data that is currently required.
You will find a good reference guide (pdf) on the official Ebean documentation page , a general description of the relationship is available in Section 11.6.2 Relationships .
4.1.2 Query section 4.1.2 Query has an example (second) that demonstrates how to get a “partial” object using select() and fetch()
biesior
source share