Exposed DAO returing null

Hello everyone.
I’m trying to use the exposed DAO but I have a problem.
I created my model this way:

class LegalPerson(id: EntityID<UUID>) : UUIDEntity(id) {
    companion object : UUIDEntityClass<LegalPerson>(LegalPersonTable)

    var internalId by LegalPersonTable.internalId
    var companyId by LegalPersonTable.companyId
    var active by LegalPersonTable.active
    var tradeName by LegalPersonTable.tradeName
    var fantasyName by LegalPersonTable.fantasyName
    var email by LegalPersonTable.email
    var cnpj by LegalPersonTable.cnpj
    var stateRegistration by LegalPersonTable.stateRegistration
    var muninipalRegistration by LegalPersonTable.muninipalRegistration
    var address by LegalPersonTable.address
    val phones by Phone referrersOn Phones.idLegalPerson
}

object LegalPersonTable : UUIDTable("person.legal_person") {
    val internalId = long("internal_id").autoIncrement().uniqueIndex()
    val companyId = uuid("company_id")
    val active = bool("active")
    val tradeName = varchar("trade_name", 100)
    val fantasyName = varchar("fantasy_name", 100)
    val email = varchar("email", 100)
    val cnpj = varchar("cnpj", 18)
    val stateRegistration = varchar("state_registration", 20)
    val muninipalRegistration = varchar("municipal_registration", 20)
    val address = uuid("address")
}

// *** PHONE ***

class Phone(id: EntityID<UUID>) : UUIDEntity(id) {
    companion object : UUIDEntityClass<Phone>(PhoneTable)

    var internalId by PhoneTable.internalId
    var phone by PhoneTable.phone
    var idLegalPerson by LegalPerson referencedOn PhoneTable.idLegalPerson
}

object PhoneTable : UUIDTable("person.phone_legal_person") {
    val internalId = long("internal_id").autoIncrement()
    val phone = uuid("phone")
    val idLegalPerson = reference("id_legal_person", LegalPersonTable)
}

And my service:

suspend fun <T> dbQuery(block: () -> T): T = withContext(Dispatchers.IO) { transaction { block() } }
    class LegalPersonService {

        suspend fun findAll() = dbQuery {
            LegalPerson.all()
        }
    }

And my router.

fun Route.legalperson(service: LegalPersonService) {
    route("/api/clients/lp") {
        get("/") {
            call.respond(service.findAll())
        }
}

But the query always returns null. And there’s data in the database.
I’m using flyway for migrations and hikariCP for pool conections

You mean that LegalPerson.all() return null or the count is 0?

Returning null

That’s very strange, you should ask on the GitHub Issue section of Exposed.
I use them Exposed at work and never had this problem. Are you on Android and using SQLite?

Webapi using postgresql version 11

Dumb me, you are using Ktor, that is not Android for sure :joy:.

Try creating some fake data in a SQLite local database using Xerial drivers and retrieve them to see if maybe the drivers are the problem.

I do not think that’s the problem.
If DLS usage works perfectly.
If I change to DAO, I can not do any operations.
There’s something I’m doing wrong. But still I have not found what.