0

I have an entity called Client:

@Entity
public class Client extends User {

    

    @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
    @OneToMany(mappedBy = "client", fetch = FetchType.LAZY)
    private Set<Activity> activities = new HashSet<>();


When I retrieve a Client object, also my nested collection are filled. Which is the best way to limit the size of these collection? I should avoid to retrieve them and manually execute a query for each collection? Which should be the best approach considering performance?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Marco Castano
  • 1,114
  • 1
  • 10
  • 25
  • Off-topic, just a friendly recommendation, please use English comments in your code, as well :) (it will be useful for future developers). – Alexandru Somai Dec 09 '21 at 08:19
  • It is a project I'm developing for studying Spring Boot :) – Marco Castano Dec 09 '21 at 08:21
  • Just to clarify - do you mean how to limit the size of the collection that is *saved* or *retrieved*? – crizzis Dec 12 '21 at 21:09
  • Does this answer your question? [Is it possible to limit the size of a @OneToMany collection with Hibernate or JPA Annotations?](https://stackoverflow.com/questions/26328187/is-it-possible-to-limit-the-size-of-a-onetomany-collection-with-hibernate-or-jp) – crizzis Dec 12 '21 at 21:10

0 Answers0