https://kotlinlang.org logo
#getting-started
Title
# getting-started
d

DMITRY.

04/19/2021, 1:29 PM
Copy code
abstract class Task<T : Enum<T>>(
    @field:Id
    @field:Indexed
    open val id: ObjectId?,
    open val group: Group
)

data class Change(
    override val id: ObjectId?,
    override val group: Group
) : Task<Status>(id, group)

enum class Group {
    FIRST,
    SECOND
}

-----


Ambiguous field mapping detected! Both private final ru.whatever.kek.tracker.model.Group ru.whatever.kek.tracker.model.task.Task.group and private final ru.whatever.kek.tracker.model.Group ru.whatever.kek.tracker.model.task.Change.group map to the same field name group! Disambiguate using @Field annotation!
but if I use @Field annotation I get this in MongoDB:
Copy code
/* 1 */
{
    "_id" : ObjectId("607d850daae5ed346803a900"),
    "incidentGroup" : "FIRST",
    "group" : "FIRST",
    "_class" : "ru.whatever.kek.tracker.model.task.Incident"
}

/* 2 */
{
    "_id" : ObjectId("607d850faae5ed346803a901"),
    "changeGroup" : "OPSSECOND,
    "group" : "SECOND",
    "_class" : "ru.whatever.kek.tracker.model.task.Change"
}

/* 3 */
{
    "_id" : ObjectId("607d8511aae5ed346803a902"),
    "maintenanceGroup" : "FIRST",
    "group" : "FIRST",
    "_class" : "ru.whatever.kek.tracker.model.task.Maintenance"
}
Fields are duplicated and I don't want to have a unique names for fields anyway How should I proceed? Thanks!
d

Dominaezzz

04/19/2021, 2:07 PM
Don't think id should be open.
Or you can make it abstract and move the annotations the change class.
30 Views