Is Hibernate equivalent to the EclipseLink batch request hint?

One thing I like about EclipseLink has this wonderful thing called a batch request hint , which I have not yet found the Hibernate equivalent to.

Basically, a whole bunch of associations becomes messy real, and you end up asking for more data than you want (remember that if you join a person at 6 addresses, information about the person returns 6 times, now continue to multiply this by additional connections).

Imagine a Person object with 0: M collections of addresses, email, phone, and order history. Combining everything that’s not good, but using the batch method:

List persons = entityManager.createQuery("select p from Person p" .setHint(QueryHints.BATCH, "p.address") .setHint(QueryHints.BATCH, "p.email") .setHint(QueryHints.BATCH, "p.phone") .setHint(QueryHints.BATCH, "p.orderHistory") .getResultList(); 

This will make a query on the Person table and it. When you first get access to the address record, it will make a single query for the entire address table. If you specified a where clause in the Person table, then the same criteria will be used to load the address.

Therefore, instead of making 1 request, you make 5.

If you did this with joins, you could get everything in one query, but you can load more data very well due to joins.

In any case, I searched the Hibernate docs for the equivalent of this, but can't see it. There is one?

+4
source share
2 answers

No.

+4
source

There are two things that I know about this:

1) hibernate.default_batch_fetch_size

2) Criteria.setFetchMode and Criteria.setFetchSize

0
source

All Articles