I have two models - Author, Book as shown below. I want to find details about an author based on age and also fetch all non-deleted books written by that author.
Author
@Entity
@Table(name = "author")
public class Author extends Model {
@Id
@Column(name = "id")
public int id;
@Column(name = "name")
public String name;
@Column(name = "age")
public int age;
@OneToMany(mappedBy = "book", cascade = CascadeType.ALL)
public List<Book> books;
private static Finder<Integer, Author> find = new Finder<Integer, Author>(Integer.class, Author.class);
public static List<Author> findByAge(int age) {
return find.fetch("books")
.where()
.eq("age", age)
.eq("books.isDeleted", false)
.findList();
}
Book Entity:
@Entity
@Table(name = "book")
public class Book extends Model {
@Id
@Column(name = "id")
public int id;
@ManyToOne(targetEntity = Author.class)
@JoinColumn(name = "author_id")
public Author author;
@Column(name = "name")
public String name;
@Column(name = "is_deleted")
public boolean isDeleted;
}
Is there something wrong with my finder in Author entity. Do I fetch all books and then filter all the non-deleted ones in Java?
Thanks in advance