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…
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)- A2% (1)
- B88% (46)
- D2% (1)
- E8% (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@Sqlannotations from a class and method are merged (MERGEvsOVERRIDE); it has no effect on transaction commit behavior, andfalseisn't even a valid value. - D.
@Sql(alwaysCommit=true)-alwaysCommitis a fabricated attribute;@Sqlexecutes SQL scripts around tests but has no such flag. - E.
@Transactional(commit=true)-commitis 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
Community Discussion
No community discussion yet for this question.