I have following entity relationship:
@Entity
public class Parent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(columnDefinition = "serial")
private Long id;
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
private List<Child> children;
}
and Child entity:
@Entity
public class Child {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(columnDefinition = "serial")
private Long id;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
private Parent parent;
}
I use Spring JPA repositories, so for calling data I use default method parentRepository.findOne(id)
I need fetch List of Parent entity where each entity of Parent will be fetched limited size of Children, for example 10.
Can you tell me if it possible with JQPL or HQL and what this select looks like? Thanks in advance.
EDIT:
Not I tried use hibernate annotation @BatchSize like this:
@BatchSize(size = 5)
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
private List<Child> children;
But didn't work, when I fetch Parent all Children are fetched.