The @BatchSize annotation of hibernate allows for batched fetching of lazy-loaded entities. E.g. if i got something like:
public class Product {
@OneToMany(fetchType=LAZY)
@BatchSize(size=10)
private ProductCategory category;
}
Now if I get the category of a product, Hibernate will fetch the categories of up to ten more products which are in the current session and have not yet had their category field initialized. This saves a ton of SQL calls to the database. So far so good. Now I wonder why would I not use the @BatchSize annotation on EVERY lazy loaded relationship? After all why would I want extra calls to the database? There clearly must be a reason for this, otherwise the Hibernate guys could have made it the default, but I currently can't see it.