////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////


== batchSize



=== Purpose


Customizes how many results are fetching during lazy loading.


=== Examples


[source,groovy]
----
class Book {
    ...
    static mapping = {
        batchSize 10
    }
}
----


=== Description


Usage: `batchSize(integer)`

Given a lazy association where an `Author` has many `Book` instances, GORM will perform one query for the `Author` and additional queries the associated `Book` instances. This is what is known as the N+1 problem and can often be worked around by using a join query. However, joins can be expensive.

Batch fetching is an optimization of lazy loading so that if, for example, you set a `batchSize` of 10 and you have an `Author` that with 30 books, instead of 31 queries you get four (one for the `Author` and three batches of 10):

[source,groovy]
----
static mapping = {
    batchSize 10
}
----

You can also configure `batchSize` on a per association basis:

[source,groovy]
----
class Author {

    static hasMany = [books: Book]

    static mapping = {
        books batchSize: 10
    }
}
----
