kotlinkotlin-exposed

Why do I get warnings for a non-nullable column returning an expected null value in a left join in Kotlin Exposed?


I'm trying out left joins in Kotlin Exposed but my logs get flooded with these warnings:

Column created_by_user.protected_identity is marked as not null, has default db value, but returns null. Possible have to re-read it from DB.

It seems that this occurs when a non-nullable column returns a null value in my left join. See an excerpt from my query below:

.leftJoin(
    Users.alias("created_by_user"),
    onColumn = { CompanyUsers.createdBy },
    otherColumn = { Users.alias("created_by_user")[Users.userSsn] },
)
.select(
    Users.columns +
    Companies.columns +
    AuthAreas.columns +
    Roles.columns +
    CompanyUsers.columns +
    Users.alias("created_by_user").columns
)

The user table in question is:

object Users : AbstractAuditable("User") {
    val userSsn: Column<PersonalId> = personalId("user_ssn").uniqueIndex()
    val customerId: Column<CustomerId?> = customerId("customer_id").nullable()
    val firstName: Column<String?> = varchar("first_name", length = 255).nullable()
    val lastName: Column<String?> = varchar("last_name", length = 255).nullable()
    val protectedIdentity: Column<Boolean> = bool("protected_identity").default(false)
}

How do I resolve these warnings? I'm reluctant to set the logs to a higher warning level as I don't want to miss other warnings / errors. And I need the default value.


Solution

  • I had the same issue when left joining non-null column. The warning disappeared when I changed the way I read the value from the ResultRow.

    I changed this:

    Table
        .leftJoin(OtherTable)
        .selectAll()
        .map { row ->
            row[OtherTable.columnName]
        }
    

    to this:

    Table
        .leftJoin(OtherTable)
        .selectAll()
        .map { row ->
            row.getOrNull(OtherTable.columnName)
        }