Entity Mapping
Stormify maps Kotlin classes to database tables using field names that match the corresponding database column names. This approach minimizes the need for extensive configuration or annotations, allowing you to work directly with your classes.
Field Name Matching
- Automatic Mapping: Fields in your classes are automatically mapped to database columns with matching names. No annotations are required as long as the field names correspond to the column names.
- Optional Annotations: You can use the
@DbTableand@DbFieldannotations to provide additional information or to customize the mapping between your classes and the database. See Annotations.
Naming Policy
Stormify provides flexible naming policies to convert class names to table names and field names to column names,
ensuring consistency across your database schema. By default, the naming policy is set to
LOWER_CASE_WITH_UNDERSCORES (snake_case).
NamingPolicy Enum Options
-
CAMEL_CASE
- Database columns use the same name as Kotlin/Java fields, preserving camel case.
- Example: Kotlin field
userName→ DB columnuserName, classUserAccount→ tableUserAccount.
-
LOWER_CASE_WITH_UNDERSCORES (default)
- Kotlin/Java camelCase names are converted to snake_case for the database.
- Example: Kotlin field
userName→ DB columnuser_name, classUserAccount→ tableuser_account.
-
UPPER_CASE_WITH_UNDERSCORES
- Kotlin/Java camelCase names are converted to SCREAMING_SNAKE_CASE for the database.
- Example: Kotlin field
userName→ DB columnUSER_NAME, classUserAccount→ tableUSER_ACCOUNT.
namingPolicy is a functional interface — you can create custom implementations:
Blacklist Management
Stormify includes a feature to manage fields that should be ignored during database interactions. This is useful when you want to exclude certain fields from being created, updated, or retrieved.
Note: If a field is marked as transient, it will be ignored by default. All three forms are recognized: JPA @javax.persistence.Transient, Kotlin @kotlin.jvm.Transient, and the Java transient keyword.
Strict Mode vs. Lenient Mode
Lenient Mode (Default)
By default, Stormify operates in lenient mode, logging warnings instead of throwing exceptions for mismatches between classes and database columns. This mode is useful for development or scenarios where flexibility is more important than strict validation.
Strict Mode
Strict mode enforces strict mapping between classes and database tables. When enabled, Stormify throws exceptions if fields are missing or do not match between the class and the database schema.
To enable strict mode: