Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PostgreSQL] Table with customEnumeration column doesn't work with Entity/DAO API #340

Closed
panjiesw opened this issue Jul 17, 2018 · 4 comments
Assignees
Labels

Comments

@panjiesw
Copy link

I have a table which uses PostgreSQL enum type. I followed the example in wiki in how to declare it in an Exposed table. I also created an entity class for the table. Something like this:

class PGEnum<T:Enum<T>>(enumTypeName: String, enumValue: T?) : PGobject() {
    init {
        value = enumValue?.name
        type = enumTypeName
    }
}

enum class Foo { Bar, Baz }

object EnumTable : LongIdTable("EnumTable") {
    val enumColumn = customEnumeration(
        "enumColumn", 
        "FooEnum", 
        { Foo.valueOf(it as String) }, 
        { PGEnum("FooEnum", it) }
    )
}

class EnumTableEntity(id: EntityID<Long>) : LongEntity(id) {
    companion object : LongEntityClass<EnumTableEntity>(EnumTable)

    val enumColumn by EnumTable.enumColumn
}

Using the entity, there is no problem in inserting new row:

EnumTableEntity.new { enumColumn = Foo.Bar }

But when I tried to query it, there is a cast exception something like can't cast PGEnum to String in valueFromDB function of ColumnType.

EnumTableEntity.findById(1L) // cast exception

If I do an insert using DSL API and then querying it, it works as expected.
Any idea?

@Tapac Tapac self-assigned this Jul 17, 2018
@Tapac Tapac added the bug label Jul 17, 2018
Tapac added a commit that referenced this issue Jul 20, 2018
@Tapac Tapac closed this as completed Jul 21, 2018
Tapac added a commit that referenced this issue Sep 29, 2018
@bvjebin
Copy link

bvjebin commented Dec 28, 2018

I am having same trouble with update using DAO.

val status: Column<Status> = customEnumeration(
            "status",
            "user_status",
            {value ->
                Status.valueOf(value.toString())},
            {it ->
                PGEnum("user_status", it)
            }).default(Status.ACCEPTED)

When I do user.status = Status.valueOf(value as String), I am getting the following exception.

java.lang.ClassCastException: com.me.commons.entities.PGEnum cannot be cast to java.lang.Enum

Any help would be appreciated.

@Tapac
Copy link
Contributor

Tapac commented Dec 28, 2018

@bvjebin, Which version of Exposed do you use?

@bvjebin
Copy link

bvjebin commented Dec 28, 2018

@Tapac 0.11.2

@lavalamp-
Copy link

lavalamp- commented Feb 10, 2020

Getting this one too, version 0.17.7

Here's the call stack when the issue crops up:

Screenshot from 2020-02-09 19-54-49

Here's the call stack when there's no issue:

Screenshot from 2020-02-09 19-57-03

Both of these call stacks originate from the exact same place in code. There's no obvious difference between the DAO objects being used in the two calls. Same transaction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants