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

AttributeConverter only supports wrapped String/Long #15

Open
tblakers opened this issue Aug 11, 2020 · 2 comments
Open

AttributeConverter only supports wrapped String/Long #15

tblakers opened this issue Aug 11, 2020 · 2 comments

Comments

@tblakers
Copy link
Contributor

tblakers commented Aug 11, 2020

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
Copy link
Collaborator

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
Copy link
Contributor Author

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)
    }
}

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

No branches or pull requests

2 participants