nerdexam
Broadcom-VMware

2V0-72.22PSE · Question #22

Which two annotations indicate that the transaction for a transactional test method should be committed after the test method has completed? (Choose two.)

The correct answer is B. @Rollback(false) C. @Commit. In Spring's test framework, @Transactional test methods roll back by default after completion to keep the database clean. @Rollback(false) explicitly disables that default rollback, forcing the transaction to commit. @Commit (introduced in Spring 4.2) is a semantic alias for…

Testing

Question

Which two annotations indicate that the transaction for a transactional test method should be committed after the test method has completed? (Choose two.)

Options

  • A@SqlMergeMode(false)
  • B@Rollback(false)
  • C@Commit
  • D@Sql(alwaysCommit=true)
  • E@Transactional(commit=true)

How the community answered

(52 responses)
  • A
    2% (1)
  • B
    88% (46)
  • D
    2% (1)
  • E
    8% (4)

Explanation

In Spring's test framework, @Transactional test methods roll back by default after completion to keep the database clean. @Rollback(false) explicitly disables that default rollback, forcing the transaction to commit. @Commit (introduced in Spring 4.2) is a semantic alias for exactly the same thing - it's a composed annotation that directly maps to @Rollback(false), making test intent clearer.

Why the distractors fail:

  • A. @SqlMergeMode(false) - This controls how @Sql annotations from a class and method are merged (MERGE vs OVERRIDE); it has no effect on transaction commit behavior, and false isn't even a valid value.
  • D. @Sql(alwaysCommit=true) - alwaysCommit is a fabricated attribute; @Sql executes SQL scripts around tests but has no such flag.
  • E. @Transactional(commit=true) - commit is not a valid attribute of @Transactional; the annotation controls propagation, isolation, timeout, and rollback rules, but not a commit flag.

Memory tip: Remember the pattern "two spellings, one meaning" - @Commit is just a readable shorthand for @Rollback(false). Both say "don't roll back." Everything else in the list (@SqlMergeMode, @Sql, @Transactional) controls something orthogonal to commit/rollback behavior, or uses attributes that don't exist.

Topics

#Spring Testing#Transaction Management#Test Annotations#@Rollback/@Commit

Community Discussion

No community discussion yet for this question.

Full 2V0-72.22PSE Practice