how can I map a one-to-many relationship in Hibernate where the many-side needs to be paginated? (i.e. you have hundreds or more related objects)
Using the OneToMany annotation (or its xml equivalent) is not useful because loading the one-side object retrieves with it all of its related objects causing a memory disaster (even though you use lazy loading).
A possible approach (which I'm already using) is to add a getter method in a DAO implementation, where you can introduce pagination parameters. However, I can see this is not ideal because you lose some features like cascading (e.g. I have to include setter methods in the DAO class to associate objects). Besides, you lose some OOP sense as the one-side object doesn't have a method to retrieve its related many-side objects. What's the best solution?
To illustrate my point further, let's say I have two classes with the following relationship among them: A has-many B.
I can't write an A.getAllB() method using a OneToMany annotation, as there are hundreds of Bs related to an A. Thus, to paginate the results I create a separate ADaoImpl class with a getAllB() method where I can include pagination params to return just one page of data at a time. Is this correct? Any help will be appreciated.