← Back to Stormify Documentation

DbTable

@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class DbTable(val name: String = "")

Marks a Kotlin class as mapping to a specific database table.

This annotation is optional. If omitted, Stormify uses the class name automatically, converting it according to the configured naming policy (default: camelCase → snake_case).

When to Use

  • Table name differs from class name

  • Table name doesn't follow naming convention

  • Need explicit mapping for clarity

Usage Examples

// Without annotation - automatic mapping
data class UserAccount(...) // Maps to table: user_account (snake_case)

// With annotation - explicit mapping
@DbTable(name = "users")
data class User(...) // Maps to table: users

// Legacy table name
@DbTable(name = "tbl_customer_info")
data class Customer(...) // Maps to table: tbl_customer_info

// Schema-qualified table (some databases)
@DbTable(name = "public.users")
data class User(...)

Naming Policy

Without @DbTable, the table name is derived from the class name using the configured policy:

  • LOWER_CASE_WITH_UNDERSCORES (default): UserAccountuser_account

  • CAMEL_CASE: UserAccountuserAccount

  • UPPER_CASE_WITH_UNDERSCORES: UserAccountUSER_ACCOUNT

// Configure naming policy
stormify.setNamingPolicy(NamingPolicy.CAMEL_CASE)

Comparison with JPA @Table

Stormify's @DbTable is compatible with JPA's @Table annotation:

// Stormify annotation
@DbTable(name = "users")
data class User(...)

// JPA annotation (also supported)
@Table(name = "users")
data class User(...)

Both work identically in Stormify. Use @DbTable for Stormify-specific projects, or @Table for JPA compatibility.

Important Notes

  • Annotation is optional - only use when needed

  • Table must exist in the database

  • Case sensitivity depends on database (MySQL: case-insensitive, PostgreSQL: case-sensitive)

  • Schema prefixes supported (e.g., schema.table_name)

See also

Properties

Link copied to clipboard

The exact name of the table in the database.