quarkus: Spring Data API Extension not working with hibernate 6

Describe the bug

Spring Data API Extension is not fully working with hibernate 6 (since 3.0.0.Alpha5). I think the current Spring Data JPA version used in quarkus is 2.1.9.Final. But I think to work with hibernate 6 the Spring Data JPA version should be updated to 3.X.X.

For example i get the following runtime exception when making a query:

Caused by: org.hibernate.query.sqm.InterpretationException: Error interpreting query [FROM CategoryDe WHERE mainEntity.id = ?1]; this may indicate a semantic (user query) problem or a bug in the parser [FROM CategoryDe WHERE mainEntity.id = ?1]
	at org.hibernate.query.hql.internal.StandardHqlTranslator.translate(StandardHqlTranslator.java:97)

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

reproducer.zip

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

3.0.0.Alpha6

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

No response

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 27 (18 by maintainers)

Most upvoted comments

Thanks a lot for looking into it @yrodiere!

Here’s a simplified version of the reproducer: reproducer-quarkus3-worksInSpring.zip

First, let me clarify one thing: this problem is mostly related to Hibernate ORM 6, so if you use Hibernate ORM 6 in Spring (e.g. Spring 6 + ORM 6.2), you will most likely hit the exact same problem.

The core of the problem is that the query method findByMainEntity(Long mainEntityId) actually relies on a “shortcut” that Hibernate ORM 5 allowed, but Hibernate ORM 6 no longer does: using an entity reference and its ID interchangeably. I.e. this method is translated to the query FROM ItemDe WHERE mainEntity = ?1, but that’s invalid in Hibernate ORM 6 and should be FROM ItemDe WHERE mainEntity.id = ?1.

So, the method should be renamed to findByMainEntityId, which will solve part of the problem.

But… there’s another problem that seems to be related to Hibernate ORM not resolving the generics correctly and thus not knowing the exact type of mainEntity. That explains the very obscure error message you experienced, and also that renaming the method to findByMainEntityId will still leave you with an error (though a different one).

I’ll create a reproducer and report that generics issue upstream.

EDIT: Reported upstream as https://hibernate.atlassian.net/browse/HHH-16378

Okay, I’ll have a look tomorrow

+1 to everything @yrodiere said 😃