Dirty Checking
What Is Dirty Checking?
Dirty checking is the process of determining which fields of an entity have changed since it was loaded from the database. When you update an entity, the ORM needs to decide:
- Whether to execute an UPDATE statement at all
- Which columns to include in the UPDATE statement
Storm's entities are stateless and immutable by design: plain Kotlin data classes or Java records with no proxies, no bytecode manipulation, and no hidden state. This design simplifies the dirty checking logic and allows for high performance.
Instead of tracking changes implicitly, Storm:
- Observes entity state when you read from the database
- Compares entity state when you call
update()within the same transaction - Generates the appropriate UPDATE statement based on the configured mode
Observed state is stored in the transaction context, not on the entity itself. This keeps entities simple and predictable while still providing intelligent update behavior.
┌─────────────────────────────────────────────────────────────────┐
│ Transaction Scope │
│ │
│ ┌─────────┐ ┌──────────────┐ ┌─────────┐ │
│ │ READ │────────▶│ Observed │────────▶│ UPDATE │ │
│ │ Entity │ │ State │ │ Called │ │
│ └─────────┘ │ (cached) │ └────┬────┘ │
│ └──────────────┘ │ │
│ │ │ │
│ ▼ ▼ │
│ ┌──────────────────────────────┐ │
│ │ Compare current entity │ │
│ │ with observed state │ │