# Limiting the number of columns from eager join fetching

**URL:** <https://discourse.hibernate.org/t/limiting-the-number-of-columns-from-eager-join-fetching/10170>\
**Category:** Hibernate ORM\
**Created:** [August 22, 2024, 5:44am UTC](https://discourse.hibernate.org/t/limiting-the-number-of-columns-from-eager-join-fetching/10170 "2024-08-22T05:44:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kennedyw](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/kennedyw/32/2337_2.png) [@kennedyw](https://discourse.hibernate.org/u/kennedyw)\
**Post date:** [August 22, 2024, 5:44am UTC](https://discourse.hibernate.org/t/limiting-the-number-of-columns-from-eager-join-fetching/10170/1 "2024-08-22T05:44:13Z")

</div>

We use a very large data model that uses 500+ entities. All of the toOne relations throughout the code are set to the default fetch type of EAGER. This hasn’t been a problem until recently, we started butting up against the database column limit just fetching one entity, because it proceeds to do over 100 left joins, fetching every column. Making some of these relations default lazy would have pretty severe downstream impact, we would have to review pretty much every access pattern to determine if we need to switch to jpql and join fetch or use entity graphs to eager fetch when necessary.

Is there any way to have it eager join fetch up until a column limit and then fetch the rest of the columns in subsequent fetches with the same predicate?

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [August 26, 2024, 1:24pm UTC](https://discourse.hibernate.org/t/limiting-the-number-of-columns-from-eager-join-fetching/10170/2 "2024-08-26T13:24:24Z")

</div>

> Is there any way to have it eager join fetch up until a column limit and then fetch the rest of the columns in subsequent fetches with the same predicate?

No, that is not possible. The thing you can control is `hibernate.max_fetch_depth`, i.e. how many nested join-fetches Hibernate can fetch in a single load. If your mapping model consists of relatively small entities, but they all have nested eager associations, this will allow you to split loads into multiple queries when reaching a certain depth.

> Making some of these relations default lazy would have pretty severe downstream impact, we would have to review pretty much every access pattern to determine if we need to switch to jpql and join fetch or use entity graphs to eager fetch when necessary.

That is the recommended way to map relationships, and especially for very large mapping models is the correct way to solve this sorts of problems. See the [fetching](https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#fetching) chapter of our user guide for more information.
