2017-08-16 81 views
2

我已經添加了一些Postgresql類型以Exposed作爲擴展。它有兩種現成的類型,名稱分別爲enumerationenumerationByName。我測試了這兩個都沒有成功將postgre枚舉類型映射到Kotlin枚舉類。在這兩種讀取和寫入它會引發錯誤如何通過Kotlin使用Postgresql枚舉類型公開的ORM?

enum class TicketStatus(val status: String) { 
    Open("open"), 
    Close("close"), 
    InProgress("in_progress") 
} 

class Ticket(id: EntityID<UUID>) : Entity<UUID>(id) { 
    companion object : EntityClass<UUID, Ticket>(Tickets) 

    var geom by Tickets.geom 
    var description by Tickets.description 
    var status by Tickets.status 
    var createdAt by Tickets.createdAt 
    var updatedAt by Tickets.updatedAt 
    var owner by Tickets.owner 
} 

讀取時:

java.lang.IllegalStateException: open is not valid for enum TicketStatus 
+0

也許是*大小寫敏感*?嘗試將元素重命名爲「打開」,「關閉」等,或者從數據庫中讀取一些大寫的名字。 – hotkey

+0

@hotkey在問題出現之前,它是如此!不起作用! – Kamyar

+0

你的「門票」對象在哪裏?你如何申報身份? –

回答

1

你應該申報狀態列如下:

object Tickets: Table() { 
    val status = enumeration("status", TicketStatus::class.java) // will create integer column 
    val status = enumerationByName("status", TicketStatus::class.java) // will create varchar with TicketStatus names 
}