Exposed DAO: Entity Classes and Relationships
Use the DAO API to map tables to entity classes and navigate relationships.
What Is the Exposed DAO Layer?
The Exposed DAO (Data Access Object) layer wraps the Query DSL with an Active Record-style API. You define Entity subclasses that map to table rows, and read/write properties directly on entity instances.
Defining an Entity
Pair a LongIdTable with an Entity subclass. Each entity class has a companion EntityClass that handles queries:
object Users : LongIdTable("users") {
val name = varchar("name", 100)
val email = varchar("email", 255)
}
class User(id: EntityID<Long>) : LongEntity(id) {
companion object : LongEntityClass<User>(Users)
var name by Users.name
var email by Users.email
}All lessons in this course
- Exposed Setup: Database Connection and Transaction DSL
- Defining Tables with the Table DSL
- CRUD with the Query DSL: insert, select, update, delete
- Exposed DAO: Entity Classes and Relationships