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.
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:
- 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()) }
}
- Generate query types using querydsl-ksp-codegen
- Observe that
QBear.species is generated as SimplePath<BearSpecies> instead of EnumPath<BearSpecies>
- 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()
- See error:
coalesce() method is not available on SimplePath
Expected behavior
The generated QBear class should have species as an EnumPath<BearSpecies>
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.
Describe the bug
When using KSP code generation with an enum field that has a JPA
@Convertannotation, the generated query type incorrectly creates aSimplePathinstead of anEnumPath. This prevents using enum-specific methods likecoalesce()and other enum operations on the generated query class.This is inconsistent with the Java APT code generator behavior, which correctly generates
EnumPathfor enum fields even when they have@Convertannotations.To Reproduce
Steps to reproduce the behavior:
@Convert:QBear.speciesis generated asSimplePath<BearSpecies>instead ofEnumPath<BearSpecies>coalesce()method is not available onSimplePathExpected behavior
The generated
QBearclass should havespeciesas anEnumPath<BearSpecies>