JPQL Joins & Fetch Joins — Concept Check
Questions on JPQL Joins & Fetch Joins. Regular JPQL JOIN does not initialise the lazy collection; JOIN FETCH forces Hibernate to load it in the same query, preventing N+1 selects for that association.
Questions in this quiz
8 questions on JPQL Joins & Fetch Joins — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.You notice a performance issue with your JPQL query that uses JOIN FETCH on a collection with pagination. What is likely happening?
- AIn-memory pagination is causing high memory usage.
- BThe collection is not being fetched due to lazy loading.
- CThe query is not fetching the collection eagerly.
- DThe query is executing multiple SQL queries instead of one.
2.A developer uses JOIN FETCH on two collections in a single query and encounters an error. What is the likely cause?
- AHibernate throws MultipleBagFetchException.
- BThe collections are not being fetched eagerly.
- CThe query is causing in-memory pagination.
- DThe query is fetching a Cartesian product.
3.What happens when you use a regular JOIN in JPQL without FETCH?
- AThe associated collection is not initialized.
- BThe query results in a Cartesian product.
- CThe SQL query includes a LEFT JOIN.
- DThe associated collection is eagerly loaded.
4.A query uses JOIN FETCH to load a customer with orders. What benefit does this provide?
- AAutomatically paginates the results in memory.
- BAllows filtering without loading the collection.
- CPrevents N+1 selects by loading associations eagerly.
- DEnsures only one SQL query is executed.
5.A developer claims that using JOIN FETCH always improves performance. What is a potential drawback?
- AJOIN FETCH never causes performance issues.
- BJOIN FETCH can lead to a Cartesian product with multiple collections.
- CJOIN FETCH does not affect performance.
- DJOIN FETCH always results in lazy loading.
6.What is a common issue when using JOIN FETCH with a Pageable parameter?
- AThe query executes multiple SQL statements.
- BThe collection is not fetched due to lazy loading.
- CThe associated entities are fetched lazily.
- DHibernate performs in-memory pagination, causing warnings.
7.A developer uses JOIN FETCH with a LIMIT clause and receives a warning. What is the warning about?
- AMultiple SQL queries being executed.
- BIn-memory pagination due to collection fetch joins.
- CLazy loading of the associated collection.
- DFetching a Cartesian product of the data.
8.What is the correct approach to handle multiple collection fetches in JPQL?
- AUse separate queries for each collection to avoid exceptions.
- BUse JOIN FETCH for all collections in one query.
- CUse LEFT JOIN FETCH to handle multiple collections.
- DIgnore the exceptions and proceed with execution.