I\'m using Ebean with the Play 2 Framework and got two models: a user model and a book model. The user model is connected with the book model in a OneToMany Relationship. So
Say you have the following models:
@Entity
public class User extends Model {
@Id
@Column(name = "user_index")
private int id;
@Column(name = "user_first_name")
private String firstName;
[...]
@OneToMany(mappedBy = "book_owner_index")
private List books;
public static Finder find = new Finder(Integer.class, User.class);
[...]
}
and
@Entity
public class Book extends Model {
@Id
@Column(name = "book_index")
private int id;
@Column(name = "book_name")
private String name;
@Column(name = "book_condition")
private String condition;
[...]
@ManyToOne
@JoinColumn(name = "book_owner_index", referencedColumnName = "user_index")
private User owner;
[...]
}
Then you can do a search like:
List users = User.find.select("*")
.fetch("books")
.where()
.eq("books.condition", "new")
.findList();