0
0
Spring Bootframework~10 mins

Read-only transactions in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to mark the transaction as read-only.

Spring Boot
@Transactional(readOnly = [1])
public void fetchData() {
    // method logic
}
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
C"true"
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string like "true" instead of boolean true.
Setting readOnly to false which means the transaction can write data.
2fill in blank
medium

Complete the code to import the correct annotation for transactions.

Spring Boot
import org.springframework.transaction.annotation.[1];

@Transactional(readOnly = true)
public void getData() {
    // method logic
}
Drag options to blanks, or click blank then click option'
AComponent
BService
CTransactional
DRepository
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated annotations like @Service or @Component.
Confusing repository annotation with transaction annotation.
3fill in blank
hard

Fix the error in the transaction annotation to make it read-only.

Spring Boot
@Transactional(readOnly = [1])
public void loadData() {
    // method logic
}
Drag options to blanks, or click blank then click option'
A"false"
Bfalse
C"true"
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using string values like "true" or "false" instead of boolean.
Setting readOnly to false which allows writes.
4fill in blank
hard

Fill both blanks to create a read-only transaction with propagation set to SUPPORTS.

Spring Boot
@Transactional(readOnly = [1], propagation = Propagation.[2])
public void queryData() {
    // method logic
}
Drag options to blanks, or click blank then click option'
Atrue
BREQUIRED
CSUPPORTS
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using false for readOnly which allows writes.
Using REQUIRED propagation which starts a new transaction.
5fill in blank
hard

Fill all three blanks to define a read-only transaction with isolation level READ_COMMITTED and timeout 30 seconds.

Spring Boot
@Transactional(readOnly = [1], isolation = Isolation.[2], timeout = [3])
public void fetchRecords() {
    // method logic
}
Drag options to blanks, or click blank then click option'
Afalse
BREAD_COMMITTED
C30
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using false for readOnly which allows writes.
Using wrong isolation level like SERIALIZABLE.
Setting timeout as a string instead of integer.