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

Panache projection handles primitive type incorrectly #43368

Open
joachimglink opened this issue Sep 18, 2024 · 4 comments · May be fixed by #41310
Open

Panache projection handles primitive type incorrectly #43368

joachimglink opened this issue Sep 18, 2024 · 4 comments · May be fixed by #41310
Assignees
Labels
area/hibernate-orm Hibernate ORM kind/bug-thirdparty Bugs that are caused by third-party components and not causing a major dysfunction of core Quarkus. kind/enhancement New feature or request

Comments

@joachimglink
Copy link

Describe the bug

I have a POJO with a constructor of some fields (some are objects like a String, others are primitive types like boolean or short).
If I do a "select new MyPojo(...)" query, it works fine and the POJO is created as expected.

But when using the #project(..) method from PanacheQuery, I get an error for a missing constructor. Only if I change the constructor of the POJO to have no primitive types but the object types (long->Long, boolean->Boolean) this works again.

Expected behavior

The Panache projection should also work with primitive types.

Actual behavior

No response

How to Reproduce?

Working:
((Session) MyEntity.getEntityManager()).createQuery("select new MyPojo(attribString, attribBoolean) from MY_ENTITY).list();

Not working:
MyEntity.find(select attribString, attribBoolean) from MY_ENTITY).project(MyPojo.class).list()

Output of uname -a or ver

No response

Output of java -version

21

Quarkus version or git rev

3.14.4

Build tool (ie. output of mvnw --version or gradlew --version)

mvn

Additional information

No response

@joachimglink joachimglink added the kind/bug Something isn't working label Sep 18, 2024
Copy link

quarkus-bot bot commented Sep 18, 2024

/cc @FroMage (panache), @loicmathieu (panache)

@yrodiere
Copy link
Member

I believe the limitation is in Hibernate ORM; created an improvement request there: https://hibernate.atlassian.net/browse/HHH-18664

@yrodiere yrodiere added kind/enhancement New feature or request triage/upstream area/hibernate-orm Hibernate ORM and removed kind/bug Something isn't working area/panache labels Sep 24, 2024
@joachimglink
Copy link
Author

@yrodiere why should it be a Hibernate limitation when the default Hibernate / JPA projection with "select new xxx(..)" is working just fine?

@yrodiere
Copy link
Member

Because Panache is also relying on Hibernate ORM for .project(), only a different feature:

// If the query starts with a select clause, we pass it on to ORM which can handle that via a projection type
if (lowerCasedTrimmedQuery.startsWith("select ")) {
// just pass it through
return new CommonPanacheQueryImpl<>(this, query, countQuery, type);
}

hibernateQuery = session.createSelectionQuery(orderBy != null ? query + orderBy : query, projectionType);

@yrodiere yrodiere self-assigned this Nov 18, 2024
@yrodiere yrodiere linked a pull request Nov 18, 2024 that will close this issue
10 tasks
@gsmet gsmet added kind/bug-thirdparty Bugs that are caused by third-party components and not causing a major dysfunction of core Quarkus. kind/bug Something isn't working and removed triage/upstream kind/bug Something isn't working labels Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM kind/bug-thirdparty Bugs that are caused by third-party components and not causing a major dysfunction of core Quarkus. kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants