Validation
Storm validates your entity and projection definitions at two levels: structural validation ensures your records follow the ORM's rules (valid primary key types, correct use of annotations, no circular dependencies), while schema validation compares your definitions against the actual database to catch mismatches before they surface as runtime errors.
Both levels are optional and configurable. Structural validation runs automatically on first use; schema validation must be explicitly enabled.
Record Validation
When Storm first encounters an entity or projection type, it inspects the record structure and validates that the definition is well-formed. This catches common modeling mistakes early, at startup rather than at query time.
What Gets Checked
Primary key rules:
- The
@PKtype must be one of:boolean,int,long,short,String,UUID,BigInteger,Enum, orRef. Floating-point types (float,double,BigDecimal) are rejected because they cannot reliably serve as identity values. - Compound keys (inline records annotated with
@PK) follow the same type restrictions for each component.
Foreign key rules:
- Fields annotated with
@FKmust be aDatatype (entity, projection, or data class with a@PK) or aRefwrapping such a type. Scalars likeStringorIntegercannot be foreign keys. - Auto-generated foreign keys (
@FK(generation = ...)) cannot be inlined.
Inline component rules:
- Fields annotated with
@Inlinemust be record types. Scalars cannot be inlined. - Inline records must not declare their own
@PK, since they are embedded within a parent entity.
Version fields:
- At most one field per entity can be annotated with
@Version. Multiple version fields are rejected.
Structural integrity:
- Records must be immutable. Mutable fields (Kotlin
var) are rejected. - Entities or projections that contain other entities or projections must annotate them as
@FKor@Inline. Storm needs to know the relationship type to generate correct SQL. - The record graph is checked for cycles. If entity A inlines entity B, which inlines entity A, the circular dependency is reported.
Configuration
Record validation runs by default and causes startup to fail on the first error. The record-mode property controls this behavior:
| Value | Behavior |
|---|---|
fail | Validation errors cause startup to fail (default). |
warn | Errors are logged as warnings; startup continues. |
none | Record validation is skipped entirely. |
This can be set as a system property, via StormConfig, or in Spring Boot's application.yml:
storm:
validation:
record-mode: fail # or "warn" or "none" (default: fail)
Schema Validation
Schema validation compares your entity and projection definitions against the actual database schema. It catches mismatches before they surface as runtime errors, similar to Hibernate's ddl-auto=validate. Storm never modifies the schema; it only reports mismatches.
What Gets Checked
| Check | Error Kind | Severity |
|---|---|---|
| Table exists in the database | TABLE_NOT_FOUND | Error |
| Each mapped column exists in the table | COLUMN_NOT_FOUND | Error |
| Kotlin/Java type is compatible with the SQL column type | TYPE_INCOMPATIBLE | Error |
| Entity primary key columns match the database primary key | PRIMARY_KEY_MISMATCH | Error |
@FK constraint references the correct target table | FOREIGN_KEY_MISMATCH | Error |
Sequences referenced by @PK(generation = SEQUENCE) exist | SEQUENCE_NOT_FOUND | Error |
Numeric cross-category conversions (e.g., Integer mapped to DECIMAL) | TYPE_NARROWING | Warning |
| Non-nullable entity field mapped to a nullable database column | NULLABILITY_MISMATCH | Warning |
Entity declares @PK but the database has no primary key constraint | PRIMARY_KEY_MISSING | Warning |
@UK field has a matching unique constraint in the database | UNIQUE_KEY_MISSING | Warning |
@FK field has a matching foreign key constraint in the database | FOREIGN_KEY_MISSING | Warning |
Errors indicate definitive mismatches that will cause runtime failures, such as missing tables or columns.
Warnings indicate situations where the mapping works at runtime but may involve subtle differences, such as precision loss when mapping a Kotlin Int to an Oracle NUMBER column. Warnings are logged but do not cause validation to fail (unless strict mode is enabled).