Hi, I'm kinda new to the Exposed framework, and I'...
# exposed
e
Hi, I'm kinda new to the Exposed framework, and I've stumbled upon this error that I can't seem to fix. Whenever I try to create a new
User
in the
Users
table (either with the
User.new
DAO method or the
Users.insert
method), an enumeration field
accountstatus
that is described as non-null, with a default value, makes the insertion fail as of `null value in column
accountstatus
violates not-null constraint` . Here is the code for the table definition and the user DAO:
Copy code
object Users : UUIDTable() {
    val email = varchar("email", 255).uniqueIndex()
    val role = enumeration<Role>("role")
    val registrationDate =
        datetime("registrationDate").default(Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()))
    val disabledDate = datetime("disabledDate").nullable()
    val accountStatus = enumeration<AccountStatus>("accountStatus").default(AccountStatus.ACTIVE)

    enum class Role {
        PROFESSOR, STUDENT
    }

    enum class AccountStatus {
        ACTIVE, DISABLED
    }
}
Copy code
class User(id: EntityID<UUID>) : UUIDEntity(id), UserData {
    companion object : UUIDEntityClass<User>(Users)

    override var email by Users.email
    override var role by Users.role
    override val registrationDate by Users.registrationDate
    override var disabledDate by Users.disabledDate
    override var accountStatus by Users.accountStatus
    val sessions by Session referrersOn Sessions.userId
}
Here is the code that throws the exception:
Copy code
// ...
transaction {
    User.new {
        email = email /* logic omitted */
        role = role /* logic omitted */
    }
}
Moreover, could someone tell me if there is a way, even if client-side and not database-enforced, to construct default values based on properties of the soon-to-be inserted row? I've read about the
clientDefault
method but I can't seem to figure out how to build a default value based on the various
Column
s. Thanks in advance, and sorry for the poor English.