Cascade Types — Concept Check
Questions on Cascade Types. CascadeType.ALL, PERSIST, MERGE, REMOVE, REFRESH, DETACH propagate operations from parent to child; avoid CascadeType.REMOVE on large collections — use bulk queries instead.
Questions in this quiz
8 questions on Cascade Types — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.An application using JPA experiences slow performance when deleting a parent entity with a large collection of child entities. What is the most likely cause?
- ACascadeType.PERSIST is incorrectly used.
- BorphanRemoval=true causes additional database queries.
- CCascadeType.DETACH is not applied.
- DCascadeType.REMOVE loads all children into memory before deletion.
2.In a JPA entity relationship, when is it appropriate to use CascadeType.ALL?
- AWhen the child entity is shared across multiple parents.
- BWhen the parent entity has a large collection of children.
- CWhen the child entity is owned and dependent on the parent.
- DWhen the child entity is independent of the parent.
3.You remove a child entity from a parent's collection, but the parent is not deleted. Which setting ensures the child entity is also deleted?
- ACascadeType.REFRESH
- BCascadeType.MERGE
- CorphanRemoval=true
- DCascadeType.DETACH
4.A developer uses CascadeType.REMOVE on a @ManyToMany relationship. What is the risk?
- AIt will detach all entities from the persistence context.
- BIt may delete shared entities still referenced by other parents.
- CIt will automatically refresh all entities involved.
- DIt will prevent any entity from being deleted.
5.What happens when em.persist(order) is called, given the cascade settings in the Order entity?
- AAll OrderItem entities are detached from the persistence context.
- BAll OrderItem entities in the items list are persisted.
- CThe Order entity is refreshed with the latest database state.
- DThe Order entity is merged with the existing database entry.
6.A developer mistakenly believes that CascadeType.ALL includes orphanRemoval. Which of the following is true?
- AorphanRemoval is only applicable to CascadeType.REMOVE.
- BorphanRemoval is included in CascadeType.ALL.
- CorphanRemoval is separate and not part of CascadeType.ALL.
- DorphanRemoval automatically applies to all cascade types.
7.Which cascade type would you use to ensure that changes to a detached entity graph are saved when re-attached?
- ACascadeType.MERGE
- BCascadeType.REFRESH
- CCascadeType.REMOVE
- DCascadeType.DETACH
8.What is a potential downside of using CascadeType.ALL inappropriately?
- AIt prevents the use of bulk operations for deletions.
- BIt automatically detaches all entities from the persistence context.
- CIt always causes performance issues due to excessive loading.
- DIt can lead to unintended deletions in shared entity relationships.