Annotation Interface BatchSize


@Target({TYPE,METHOD,FIELD}) @Retention(RUNTIME) public @interface BatchSize
Specifies a maximum batch size for batch fetching of the annotated entity or collection.

When batch fetching is enabled, Hibernate is able to fetch multiple instances of an entity or collection in a single round trip to the database. Instead of a SQL select with just one primary key value in the where clause, the where clause contains a list of primary keys inside a SQL in condition. The primary key values to batch fetch are chosen from among the identifiers of unfetched entity proxies or collection roles associated with the session.

For example:

   @Entity
   @BatchSize(size = 100)
   class Product {
       ...
   }

will initialize up to 100 unfetched Product proxies in each trip to the database.

Similarly:

   @OneToMany
   @BatchSize(size = 5) /
   Set<Product> getProducts() { ... };

will initialize up to 5 unfetched collections of Products in each SQL select.

See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    int
    The maximum batch size, a strictly positive integer.