Skip to content

Case When enum: Could not determine ValueMapping for SqmParameter #959

@chadongmin

Description

@chadongmin

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 CaseBuilder in QueryDSL with an Enum value directly in .then() or .otherwise(), a JpaSystemException occurs, caused by a ConversionException: Could not determine ValueMapping for SqmParameter. This happens because Hibernate fails to map the Enum object to a valid SQL parameter in the generated query.

To Reproduce
Steps to reproduce the behavior:

  1. Create a QueryDSL query using JPAQueryFactory.
  2. Use CaseBuilder with a subquery in the SELECT clause.
  3. Pass an Enum object (e.g., FollowStatus.FOLLOWING) directly to .then() and .otherwise().
  4. Execute the query with Hibernate (e.g., version 6.2.22) and QueryDSL (e.g., version 5.0.0).
  5. Observe the error: org.hibernate.query.sqm.sql.ConversionException: Could not determine ValueMapping for SqmParameter.

Example code:

QFollow f2 = new QFollow("f2");
queryFactory
    .select(Projections.constructor(
        RelationUserInfo.class,
        follow.userId,
        new CaseBuilder()
            .when(JPAExpressions.selectOne().from(f2).where(f2.userId.eq(1L)).exists())
            .then(FollowStatus.FOLLOWING)
            .otherwise(FollowStatus.UNFOLLOW).as("status")
    ))
    .from(follow)
    .fetch();

Expected behavior
The query should execute successfully, with the Enum value (FollowStatus.FOLLOWING or FollowStatus.UNFOLLOW) properly mapped to a string or ordinal in the SQL query, resulting in a valid result set without exceptions.

Screenshots
N/A (Error is stack trace-based; see stack trace below):

org.springframework.orm.jpa.JpaSystemException: ...
Caused by: org.hibernate.query.sqm.sql.ConversionException: Could not determine ValueMapping for SqmParameter: SqmPositionalParameter(2)

Desktop (please complete the following information):

  • OS: [Mac]
  • Browser [N/A]
  • Version [QueryDSL 5.0.0, Hibernate 6.2.22, Spring Boot 3.1.0]

Smartphone (please complete the following information):

  • Device: [N/A]
  • OS: [N/A]
  • Browser [N/A]
  • Version [N/A]

Additional context
This issue appears to stem from an incompatibility or limitation in how QueryDSL’s CaseBuilder handles Enum objects when generating expressions for Hibernate. A workaround involves using .name() to pass the Enum as a string, but this requires additional DTO adjustments. I suspect the root cause is in the CaseBuilder expression mapping logic, which fails to convert the Enum to a compatible Hibernate parameter type.

Since this would be my first contribution to QueryDSL, I’d like to kindly ask: if this issue hasn’t been resolved yet, would it be acceptable for me to submit a PR to address it?

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