Entity Graphs — Concept Check
Questions on Entity Graphs. @EntityGraph specifies which associations to load for a specific query without changing the mapping's default fetch type; load hints override EAGER/LAZY per query.
Questions in this quiz
8 questions on Entity Graphs — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.You have a Spring Data JPA repository method that needs to fetch an Order with its customer and items eagerly. Which approach should you use?
- ASet fetch type to EAGER in the entity
- BUse @EntityGraph with a named graph
- CUse a native SQL query with JOIN
- DUse JOIN FETCH in a custom query
2.A developer notices that a query with JOIN FETCH is causing memory issues during pagination. What is likely happening?
- AJOIN FETCH doesn't support eager loading
- BJOIN FETCH loads all rows before paginating
- CJOIN FETCH causes N+1 problem
- DJOIN FETCH ignores entity mappings
3.What is the role of @NamedEntityGraph in JPA?
- ASpecifies lazy loading for all associations
- BOverrides default fetch type globally
- CDefines reusable entity graphs on an entity
- DAutomatically optimizes query performance
4.A service uses an ad-hoc entity graph with GraphType.FETCH. What is the behavior for unlisted associations?
- AThey are treated as EAGER
- BThey are ignored in the query
- CThey use default mapping
- DThey are treated as LAZY
5.Why might a developer choose @EntityGraph over JOIN FETCH for a Spring Data JPA method?
- A@EntityGraph supports pagination
- BJOIN FETCH doesn't support eager loading
- CJOIN FETCH is faster
- D@EntityGraph is easier to write
6.A developer uses @EntityGraph with attributePaths set to 'customer' and 'items.product'. What happens if 'items' is not listed?
- A'items' is ignored completely
- B'items' is loaded lazily
- C'items' causes a query error
- D'items' is eagerly loaded by default
7.What is a potential issue when using JOIN FETCH with multiple bag collections?
- AIt can cause a Cartesian product
- BIt does not support eager loading
- CIt automatically optimizes queries
- DIt only fetches one collection
8.A developer wants to load only the customer association eagerly for an Order entity. Which named entity graph should they use?
- AOrder.defaultGraph
- BOrder.withCustomerAndItems
- COrder.withCustomerOnly
- DOrder.lazyLoadGraph