Limit @OneToMany List

0

Good morning everyone! I have some problems in a list that in some cases I do not need to return it completely

@OneToMany(mappedBy="local", cascade=CascadeType.ALL, fetch = FetchType.EAGER)
@OrderBy("dataContagem DESC")
private List<Contagem> contagens;

I've tried using the validation constraint @Size and @Max. I am using Hibernate with the JPA specification. Is it possible to perform this limitation of the OneToMany list in the JPQL query?

    
asked by anonymous 04.12.2018 / 12:46

1 answer

0

I found this answer that should meet your need in the stackoverflow-en

@OneToMany(mappedBy="local", cascade=CascadeType.ALL)
@OrderBy("dataContagem DESC")
@Fetch(FetchMode.SELECT)
@Size(min=1, max=10)
private List<Contagem> contagens;

Remove the fetch EAGER because it can cause overload if it is used with a list and has many records, look for the contagens.size(); before sending the object, the active proxy will make the selection of contagens

    
04.12.2018 / 15:22