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.
org.hibernate.cfg.AvailableSettings#DEFAULT_BATCH_FETCH_SIZE
| Modifier and Type | Method and Description |
|---|---|
| public int |
| size | back to summary |
|---|---|
| public int size() The maximum batch size, a strictly positive integer.
Default is defined by | |