title: Is it possible to limit the size of a @OneToMany collection with Hibernate or JPA Annotations?
body: <p>If I have the following mapped collection in a POJO using JPA/Hibernate Annotations:</p>
  
  <pre><code>@OneToMany(mappedBy = "columnName", fetch = FetchType.LAZY)
  @OrderBy("aField")
  @MapKeyJoinColumn(name = "id_fk")
  @LazyCollection(value = LazyCollectionOption.EXTRA)
  private Set&lt;PojoClass&gt; collection = new HashSet&lt;&gt;();
  </code></pre>
  
  <p>Is it possible to limit the size of the loaded collection to a specific number n or to set the page size to lazy load the first n elements of the collection without loading all the items or any other items from other instances of the class (like with @BatchSize)?</p>
  
  <p>Notice that the question explicitly refers to POJO mappings, not making additional queries, using Criteria or any other way to programmatically limit the size in explicit queries.</p>
  
  <p>Possible solutions I've been looking at are finding an implementation of the SQL TOP statement within Hibernate, hopefully as an annotation or create a custom CollectionPersister to modify the generated query (although this would require having the TOP statement implemented within the supported dialects).</p>