QuizzesTransactions in JPA — Concept Check
intermediate
hibernate

Transactions in JPA — Concept Check

Questions on Transactions in JPA. JPA transactions are demarcated by EntityTransaction or (in Spring) @Transactional; a transaction spans the persistence context lifecycle for a unit of work.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Transactions in JPA — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.In a Spring application, what happens when a @Transactional method throws a checked exception?

    • AThe transaction does not roll back unless configured.
    • BThe transaction commits, ignoring the exception.
    • CThe transaction pauses until resolved.
    • DThe transaction rolls back automatically.
  2. 2.A developer sets FlushModeType to COMMIT for a read-heavy operation. What is the likely effect?

    • AReduced database flush operations.
    • BIncreased consistency within the transaction.
    • CQueries return stale data.
    • DIncreased transaction overhead.
  3. 3.What happens to an entity when a transaction commits in JPA?

    • AIt becomes managed.
    • BIt is automatically removed.
    • CIt remains in the new state.
    • DIt becomes detached.
  4. 4.A method annotated with @Transactional(readOnly = true) is used. What is the primary benefit?

    • AAutomatically rolls back on exceptions.
    • BPrevents any database write operations.
    • COptimizes flush and snapshot behavior.
    • DEnsures entities remain managed.
  5. 5.You call em.persist() on a new entity within a transaction. What state is the entity in?

    • ANew
    • BManaged
    • CDetached
    • DRemoved
  6. 6.A developer notices a SELECT followed by an UPDATE and another SELECT. What might be the cause?

    • AIncorrect entity state management.
    • BTransaction boundary misconfiguration.
    • CEntityManager misusage.
    • DFlushModeType.AUTO causing intermediate flushes.
  7. 7.What is the effect of calling em.merge() on a detached entity?

    • AIt transitions to a removed state.
    • BIt becomes managed again.
    • CIt is persisted as new.
    • DIt remains detached.
  8. 8.In a JPA transaction, what is the default behavior when a RuntimeException is thrown?

    • AThe transaction commits.
    • BThe transaction continues.
    • CThe transaction rolls back.
    • DThe transaction pauses.