AttributeConverter only supports wrapped String/Long
tblakers opened this issue · 2 comments
tblakers commented
My domain model contains inline classes wrapping UUIDs. I'd like to be able to store these using the native Postgres UUID type, and this is allowed by JPA AttributeConverter class. Unfortunately the processor requires the target type to be either a Long or a String.
private fun converterFunc(name: String, type: TypeName, it: ConverterDefinition, fileSpec: FileSpec.Builder) {
val wrapperName = when (it.targetType.asClassName()) {
STRING -> "stringWrapper"
LONG -> "longWrapper"
else -> throw TypeConverterNotSupportedException(it.targetType)
}
Is there any particular reason for this, and if not would you accept a PR that adds UUID as an option?
pjagielski commented
Yes, for now we only support Long ang String, having UUID sounds like a resonable idea. Do you have any converter code that transforms your classes into UUIDColumnType
?
tblakers commented
In Postgres at least, UUID is a native type, so a converter is very simple:
data class MyUUID(id: UUID)
class MyUUIDConverter : AttributeConverter<MyUUID, UUID> {
override fun convertToDatabaseColumn(attribute: MyUUID): UUID {
return attribute.id
}
override fun convertToEntityAttribute(dbData: UUID): MyUUID {
return MyUUID(dbData)
}
}