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

QueryDSL-JPA + Custom type implementing Number + NumberExpression #3550

Open
HonoluluHenk opened this issue Jul 21, 2023 · 6 comments
Open
Labels

Comments

@HonoluluHenk
Copy link

HonoluluHenk commented Jul 21, 2023

Observed vs. expected behavior

When using the following Combination

  • a custom Type extending Number, converted using JPA @Converter/AttributeConverter (also happens with all other Hibernate custom types like UserType)
  • a NumberExpression in the JPAQuery like sum()

Example:

var rows = new JPAQuery<>(em)
		.select(myEntity.myCustomNumber.sum())
		.from(myEntity)
		.fetch();

Actual outcome:
I receive java.lang.IllegalArgumentException: Unsupported target type : MyCustomNumber instead of a valid result.

Expected outcome:
The query-result.

Steps to reproduce

I created a reproducer with unit tests showing what works and what doesn't:
https://github.com/dvbern/bug-reproducers-querydsl-jpa-hibernate6

Environment

Querydsl version: 5.0.0-jakarta (does not look like a jakarta-problem, though)

Querydsl module: querydsl-jpa/querydsl-core

Database: any (e.g. hsqldb, postgresql)

JDK: 17 (but the stacktrace indicates this is not a JDK-problem)

Additional details

Works correctly - at least "as expected" :) - in the old Hibernate 5.

(Edit: QueryProjection and Hibernate6 is not necessary. I updated Description + Title accordingly)

@HonoluluHenk HonoluluHenk changed the title QueryDSL-JPA + Hibernate 6 + QueryProjection + Converter QueryDSL-JPA + Hibernate 6 + NumberExpression + Converter Jul 21, 2023
@jwgmeligmeyling
Copy link
Member

I’m not so sure if Converters ever “worked as intended” for Hibernate 5 as well: #2652

The problem is that the JPA specification doesnt really specify how converted fields should be treated in JPQL, leading to different expectations and implementations in JPA vendors.

@velo
Copy link
Contributor

velo commented Dec 4, 2023

Hi,

I have forked this project and we just released a released a milestone to maven central that is compatible with hibernate 6.
https://repo1.maven.org/maven2/io/github/openfeign/querydsl/querydsl-core/6.0.0.M1/

If you can, please try 6.0.0.M1 and let us know how it goes.

Also note the artifact GAV changed:

    <dependency>
      <groupId>io.github.openfeign.querydsl</groupId>
      <artifactId>querydsl-jpa</artifactId>
      <version>6.0.0.M1</version>
    </dependency>

@HonoluluHenk
Copy link
Author

I just tried your fork and switched from foo.sum() to foo.sumAggregate() and ran into the exact same error.
Your fork provides foo.sumBigDecimal which is at least a working workaround.

Would you like me to continue this bug-report on your forked repo?

@velo
Copy link
Contributor

velo commented Jan 18, 2024

Yes please

@HonoluluHenk
Copy link
Author

Discussion continued on the OpenFeign issue

@HonoluluHenk
Copy link
Author

To all coming here from google: the bug is not related to Hibernate 6 but a custom type somehow implementing Number

@HonoluluHenk HonoluluHenk changed the title QueryDSL-JPA + Hibernate 6 + NumberExpression + Converter QueryDSL-JPA + NumberExpression + Converter Jan 22, 2024
@HonoluluHenk HonoluluHenk changed the title QueryDSL-JPA + NumberExpression + Converter QueryDSL-JPA + Custom type implementing Number + NumberExpression Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants