Hi all,
Any reason why setting a large batch-size, say batch-size = 100, is particularly bad?
Everything I've read about batch-size on Entities or collections say to keep this number small, preferably under 10.
I have a worst-case scenario that returns hundreds (possibly 2 or 3 thousand) of Items. The average case is most likely under a hundred.
As you can see from the sample mappings below, each Item has two collections that are not lazy loaded. This results in an additional 2 queries per Item returned.
If there are M Items to return, and the batch-size is set to N on both collections, the number of queries is roughly 2*M/N. My current configuration confirms this.
What are the side-effects of specifying a large batch-size?? E.g. I'd like to set the batch-size = 100, so for our large users this would result in only a dozen queries at most. Any reason why this would be bad, besides memory considerations?
My gut tells me that this is a bad thing, but I can't think of a concrete reason (except for memory considerations and large generated SQL), why this would be bad.
Even if batch-size = 1, the heap still has to handle 2 thousand items.
The only other thing is that the generated SQL underneath could potentially be very big with all the added (alias0.id=?) OR (alias0.id=?) OR ....
Thanks!
Hibernate version: Hibernate 2.1.7
Mapping documents:
These are sample mappings.
Code:
<class name="Item" table="items" discriminator-value="4" polymorphism="explicit">
<id name="id" column="id" access="field" unsaved-value="-2147483648">
<generator class="identity"/>
</id>
<discriminator column="discriminator" type="integer"/>
<property name="userName"/>
<set name="dogs" table="mapItemToDogs"
cascade="none" access="field" batch-size="10">
<key column="itemID"/>
<many-to-many class="Dog" column="dogId"/>
</set>
<set name="cats"
cascade="all-delete-orphan" access="field" batch-size="10">
<key column="itemID"/>
<one-to-many class="Cat"/>
</set>
</class>
Sample HQL query:Code:
from Item i where i.userName = :userName
Database: SQLServer 2000