Skip to content

[KSP Codegen] Enum fields with @Convert annotation incorrectly generate SimplePath instead of EnumPath #1410

@jbl428

Description

@jbl428

Important Notice

Thank you for opening an issue! Please note that, as outlined in the README, I currently only work on feature requests or bug fixes when sponsored. Balancing this project with professional and personal priorities means I have a very limited amount of effort I can divert to this project.

You must put in the work to address this issue, or it won't be addressed.

  • I am willing to put in the work and submit a PR to resolve this issue.

Describe the bug

When using KSP code generation with an enum field that has a JPA @Convert annotation, the generated query type incorrectly creates a SimplePath instead of an EnumPath. This prevents using enum-specific methods like coalesce() and other enum operations on the generated query class.

This is inconsistent with the Java APT code generator behavior, which correctly generates EnumPath for enum fields even when they have @Convert annotations.

To Reproduce

Steps to reproduce the behavior:

  1. Create an entity with an enum field annotated with @Convert:
@Entity
class Bear(
    @Id val id: Int,
    val name: String,
    @Convert(converter = BearSpeciesConverter::class)
    val species: BearSpecies?
)

enum class BearSpecies { BROWN_BEAR, BLACK_BEAR, POLAR_BEAR }

@Converter
class BearSpeciesConverter : AttributeConverter<BearSpecies, String> {
    override fun convertToDatabaseColumn(attribute: BearSpecies?): String? = attribute?.name?.lowercase()
    override fun convertToEntityAttribute(dbData: String?): BearSpecies? = 
        dbData?.let { BearSpecies.valueOf(it.uppercase()) }
}
  1. Generate query types using querydsl-ksp-codegen
  2. Observe that QBear.species is generated as SimplePath<BearSpecies> instead of EnumPath<BearSpecies>
  3. Try to use enum-specific operations:
val q = QBear.bear
queryFactory.select(QBearSimplifiedProjection(q.id, q.name, q.species.coalesce(BearSpecies.BLACK_BEAR)))
    .from(q)
    .fetchOne()
  1. See error: coalesce() method is not available on SimplePath

Expected behavior

The generated QBear class should have species as an EnumPath<BearSpecies>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions