<@U01SP2GJYAU> If I want to make an interface with...
# komapper
d
@Toshihiro Nakamura If I want to make an interface with common fields that I need in a few tables, can I annotate them (with things like
@KomapperColumn
) there instead of on the data class they inherit?
t
No, you can’t. If we support that, specifying annotations would be prone to conflicts because a class can implement multiple interfaces.
d
Ok, thanks! My use case is for things like create_date, and update_data that are common amongst a bunch of tables... would there be another way to define common fields (apart from using Embedded...)
t
No, there is not. Could you tell me why you do not want to use Embedded?
d
If I could somehow delegate to it's fields I wouldn't mind... but what would I regroup something like created_at created_by updated_at updated_by into? It looks not-so-clean... I'd understand embedding address details though...
t
I’m not sure if this is the method you’re looking for, but how about this approach?
Copy code
data class Common(
    @KomapperCreatedAt
    val createdAt: LocalDateTime? = null, 
    @KomapperUpdatedAt
    val updatedAt: LocalDateTime? = null,
)

interface CommonAware {
    val common: Common
}

val CommonAware.createdAt 
    get() = common.createdAt

val CommonAware.updatedAt
    get() = common.updatedAt

@KomapperEntity
data class Dept(
    @KomapperId
    val id: Int,
    @KomapperEmbedded
    override val common : Common = Common()
) : CommonAware
You can use the above entity class as follows:
Copy code
val dept = Dept(1)
val timestamp = dept.updatedAt
d
Yeah, I guess that's one way of doing it... but I still have the extra boilerplate, also when using projections, I'd need to use those funny property names... but I could keep that in mind if I come across a nicer use case... thanks!
👍 1