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

Unable to use dynamic named queries on hibernate-orm #36441

Closed
i96751414 opened this issue Oct 12, 2023 · 9 comments · Fixed by #38283
Closed

Unable to use dynamic named queries on hibernate-orm #36441

i96751414 opened this issue Oct 12, 2023 · 9 comments · Fixed by #38283
Labels
area/hibernate-orm Hibernate ORM area/persistence kind/bug Something isn't working triage/upstream Used for issues which are caused by issues in upstream projects/dependency
Milestone

Comments

@i96751414
Copy link

Describe the bug

Hello,

I just realised it is not possible to use typed queries (where the result class is an entity - annotated with @entity) for named queries which are created dynamically (using hibernate-orm).

When using the below approach:
entityManager.getEntityManagerFactory().addNamedQuery("name", entityManager.createNativeQuery("sql string", ResultClassEntity.class));

and then getting the created query through:
entityManager.createNamedQuery("name", ResultClassEntity.class)

the following exception is thrown:
java.lang.IllegalArgumentException: Named query exists, but did not specify a resultClass

Kindly

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

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

No response

Additional information

No response

@i96751414 i96751414 added the kind/bug Something isn't working label Oct 12, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Oct 12, 2023

/cc @Sanne (hibernate-orm), @gsmet (hibernate-orm), @yrodiere (hibernate-orm)

@yrodiere
Copy link
Member

Hello,

Thanks for reporting.

It would help a lot if your could please provide a self-contained reproducer, i.e. a Quarkus project that attempts to do this and should work, but does not.

@yrodiere yrodiere added the triage/needs-reproducer We are waiting for a reproducer. label Oct 12, 2023
@yrodiere
Copy link
Member

yrodiere commented Nov 7, 2023

Hey,

Did you have time to work on a reproducer?

@i96751414
Copy link
Author

Hello.

My apologies for not having submitted a reproducer - I will try to generate one until the end of the week.

Cheers

@yrodiere
Copy link
Member

Hey @i96751414, any news on that reproducer?

Thanks.

@yrodiere yrodiere added triage/needs-reproducer We are waiting for a reproducer. and removed triage/needs-reproducer We are waiting for a reproducer. labels Nov 20, 2023
@i96751414
Copy link
Author

Apologies for the delay in creating the reproducer.
This is a very simple and quick example, which only does 2 things:
1 - Add an item to a DB
2 - Get the item from the DB (the part which is failing here)

See dynamic-named-queries.zip

@geoand geoand removed the triage/needs-reproducer We are waiting for a reproducer. label Dec 12, 2023
@yrodiere
Copy link
Member

Thank you @i96751414 , we will have a look.

@yrodiere
Copy link
Member

So... this seems to be a bug in Hibernate ORM itself: https://hibernate.atlassian.net/browse/HHH-17566

I think you could work around the problem by using non-native (HQL) queries.

@yrodiere yrodiere added the triage/upstream Used for issues which are caused by issues in upstream projects/dependency label Dec 14, 2023
@yrodiere
Copy link
Member

yrodiere commented Dec 14, 2023

To clarify, I reported the bug to the Hibernate ORM team and we'll wait for it to be solved upstream.

Thanks for reporting!

@quarkus-bot quarkus-bot bot added this to the 3.9 - main milestone Jan 18, 2024
@gsmet gsmet modified the milestones: 3.9 - main, 3.7.0 Jan 23, 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 area/persistence kind/bug Something isn't working triage/upstream Used for issues which are caused by issues in upstream projects/dependency
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants