Suppose I have a Post entity and a Comment entity and a one to many relationship:
@Entity class Post {
...
@OneToMany
List comments;
Is it possible to emulate dynamic paging with @OneToMany collections on top of JPA (...)
Not supported. The standard approach would be to use a JPQL query to retrieve the comments for a given post and and to use Query#setFirstResult(int)
and Query#setMaxResults(int)
.
On my first thought, we could create a subclass of List, (...). But I don't know whether Hibernate/JPA will recognize this, or interfere with it.
It obviously won't without an heavy patch to drastically change the default behavior.