Annotations
Stormify supports both its own annotations (@DbTable, @DbField) and standard JPA annotations (@Id, @Table, @Column, etc.) — see JPA annotations below.
@DbTable Annotation
The @DbTable annotation marks a Kotlin class as a Stormify entity. It serves two roles:
- Signals the class to the annotation processor so it emits the metadata registrar and type-safe PagedList paths (
Foo_.name). This is required on Native/Android/iOS (no runtime reflection) and on any target that uses typed paths. - Overrides the table name when the database table doesn't match the class name under the current naming policy.
When the table name already matches the policy (e.g. class User ↔ table user), use @DbTable without arguments as a pure marker. Provide name = "..." only when the database table name differs.
Attributes
name: Specifies the name of the table in the database. If not provided, the class name will be used, converted using the current naming policy.
Example
import onl.ycode.stormify.DbTable
import onl.ycode.stormify.DbField
// Marker only — table name is derived from the class name
@DbTable
data class User(
@DbField(primaryKey = true)
var id: Int = 0,
var name: String = ""
)
// Explicit table name — different from what the naming policy would produce
@DbTable(name = "tbl_legacy_customer")
data class Customer(
@DbField(primaryKey = true)
var id: Int = 0,
var name: String = ""
)
import onl.ycode.stormify.DbTable;
import onl.ycode.stormify.DbField;
// Marker only — table name is derived from the class name
@DbTable
public class User {
@DbField(primaryKey = true)
private int id;
private String name;
// getters and setters
}
// Explicit table name — different from what the naming policy would produce
@DbTable(name = "tbl_legacy_customer")
public class Customer {
@DbField(primaryKey = true)
private int id;
private String name;
// getters and setters
}
@DbField Annotation
The @DbField annotation provides additional information about a specific field. This annotation
is optional and allows you to customize how fields are mapped to database columns.
Attributes
name: Specifies the name of the field in the database. If not provided, the field name in the class will be used, converted using the current naming policy.primaryKey: Indicates whether the field is a primary key. Defaults tofalse.primarySequence: Specifies the name of the primary key sequence in the database. If not provided, the primary key value generation relies on the database.autoIncrement: Indicates the field value is auto-generated by the database (AUTO_INCREMENT, SERIAL, IDENTITY). When true, the field is excluded from INSERT statements and its value is read back after insertion. Defaults tofalse.creatable: Determines whether the field can be used when creating a new record. Defaults totrue.updatable: Determines whether the field can be used when updating a record. Defaults totrue.enumAsString: Whentrue, stores enum values as their string name instead of an integer. Defaults tofalse. See Enums.
Example
In this example:
- The
idfield is mapped to thecustom_idcolumn, marked as a primary key, and uses a sequence namedid_seq. - The
namefield is configured to be updatable but not creatable.
Other Supported Annotations
Stormify provides support for several standard annotations from the javax.persistence package (JPA), making it easy to integrate with existing applications. The following annotations are supported:
-
@Id: Marks a field as the primary key of the entity. -
@Table: Specifies the table in the database that maps to the entity. Stormify uses the table name from this annotation to map your classes to the corresponding database tables. -
@Column: Maps a field to a specific column. Stormify reads thename,insertable, andupdatableattributes. -
@JoinColumn: Specifies the column used for joining an entity association. Stormify reads thename,insertable, andupdatableattributes. -
@SequenceGenerator: Defines a primary key generator that uses a database sequence, using thenameattribute to specify the sequence name. -
@GeneratedValue: When used withstrategy = GenerationType.IDENTITY, marks a field as auto-generated by the database (equivalent to@DbField(autoIncrement = true)). -
@Enumerated: Controls how enum fields are stored.@Enumerated(EnumType.STRING)stores the enum name as a string (equivalent to@DbField(enumAsString = true)).@Enumerated(EnumType.ORDINAL)(or omitting the annotation) stores the ordinal integer. -
@Transient: Marks a field to be ignored during database operations. All three forms are supported: JPA@javax.persistence.Transient, Kotlin@kotlin.jvm.Transient, and the Javatransientkeyword.
These annotations help bridge the gap between your classes and the database schema. By leveraging standard JPA annotations, Stormify ensures compatibility with existing JPA setups while providing additional flexibility.
Annotation Processor (annproc)
Stormify needs entity metadata (field names, types, primary keys) to perform ORM operations. There are two ways to provide this metadata:
- Reflection (JVM only):
kotlin-reflectdiscovers metadata at runtime. This is the default —kotlin-reflectis included as a transitive dependency ofstormify-jvm. - Annotation Processor: The
annprocKSP processor generates metadata at compile time by scanning@DbTableand JPA@Entityannotations.
On Native/Android/iOS, reflection is not available — annproc is required.
On JVM, annproc is optional but offers faster startup since metadata is pre-computed.
Setup
Add the KSP plugin and annproc dependency:
KSP requires the Kotlin compiler, so pure Java/Maven projects without a Kotlin compilation
step cannot use annproc — they rely on kotlin-reflect instead.
The processor generates an EntityRegistrar object. Pass it to the Stormify constructor:
Excluding kotlin-reflect
When using annproc on JVM, kotlin-reflect is no longer needed at runtime. You can
exclude it to reduce the dependency footprint: