-
-
Notifications
You must be signed in to change notification settings - Fork 72
Description
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:
- 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 asSimplePath<BearSpecies>
instead ofEnumPath<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 onSimplePath
Expected behavior
The generated QBear
class should have species
as an EnumPath<BearSpecies>