Performance: Read-only transactions
MEDIUM IMPACT
Read-only transactions reduce database locking and improve query performance, impacting server response time and user experience.
@Transactional(readOnly = true)
public List<User> getUsers() {
return userRepository.findAll();
}@Transactional
public List<User> getUsers() {
return userRepository.findAll();
}| Pattern | Database Locks | Transaction Overhead | Query Speed | Verdict |
|---|---|---|---|---|
| Read-write transaction for read-only query | High locks | Higher overhead | Slower | [X] Bad |
| Read-only transaction for read-only query | Minimal locks | Lower overhead | Faster | [OK] Good |