Viktar Patotski
Viktar Patotski

@xpvit

3 Tweets 20 reads Feb 28, 2023
⚠️#Spring Data JPA Performance Tip:⚠️
Mark the transaction handling class with @Transactional(readOnly=true) and mark modifying methods as just @Transactional. ReadOnly disables dirty-checking on read-only methods and speeds up your application. 👇
As a bonus, you get extra protection from modifying any entities in read-only methods by calling their setters unintentionally. Example:
@Transactional(readOnly=true)
class UserService {
getAll()
getById(...)
getByName
@Transactional
createUser(User u)
}
@transactional If you find this tip useful:
1. Follow me @xpvit for more Java, Cloud, and Linux knowledge.
2. RT the tweet below to share this thread with your audience

Loading suggestions...