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?
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 chapter of our user guide for more information.