Skip to content

IllegalArgumentException when creating named native query via Shared EntityManager with Hibernate 8.0.0-SNAPSHOT / JPA 4.0.0-M4 #36878

@oscarfanchin

Description

@oscarfanchin

IllegalArgumentException when creating named native query via SharedEntityManager with Hibernate 8.0.0-SNAPSHOT / JPA 4.0.0-M4

Hello,

I am currently exploring Jakarta Persistence 4.0 support in the Spring Data JPA ecosystem and, while doing that, I ran into a problem that I tried to isolate in a minimal standalone reproducer.

To avoid interference from other layers as much as possible, I prepared a small reproduction project using only Spring Framework and Hibernate ORM, with the latest snapshot/milestone versions available to me. In particular, the problematic scenario occurs with:

  • Spring Framework 7.1.0-SNAPSHOT
  • Hibernate ORM 8.0.0-SNAPSHOT
  • Jakarta Persistence 4.0.0-M4

As a baseline for comparison, the same reproducer also includes a profile using earlier stable versions, where this behavior does not occur.

For the domain/test model, instead of creating an ad hoc example from scratch, I preferred to reuse the same entity class imported from Spring Data tests, so that I could start from an already realistic case and focus only on isolating the behavior.

At the moment I focused on the first scenario I was able to isolate clearly and reproduce consistently: creating a named native query through Spring's SharedEntityManager.

I cannot rule out that there may be other similar cases, but for now I preferred to start from this specific example and keep the reproducer as small and focused as possible.

In the reproducer:

  • with the baseline profile, the test passes and the query is created successfully;
  • with the profile using Hibernate 8 / JPA 4.0, the call to EntityManager#createNamedQuery(...) fails with an IllegalArgumentException.

The Hibernate 8 test is therefore also green, but only because it explicitly asserts the expected failure, i.e. the exception observed in this scenario, and prints the full stack trace to make inspection easier.

I collected everything in a small standalone reproduction repository so that the case is easy to run and, if needed, easy to extend with additional query variants or version combinations.

Reproducer

Repository: oscarfanchin/test-spring-h8

Steps to reproduce

Run the baseline profile:

mvn test

Run the Hibernate 8 / JPA 4.0 profile:

mvn test -Ph8-jpa4

Observed behavior

Under the Hibernate 8 / JPA 4.0 profile, calling:

em.createNamedQuery("User.findByNativeNamedQueryWithPageable")

fails with an IllegalArgumentException.

java.lang.IllegalArgumentException: methods with same signature setProperties(java.util.Map) but incompatible return types: [interface org.hibernate.query.MutationOrSelectionQuery, interface org.hibernate.query.sql.spi.NativeQueryImplementor] at java.base/java.lang.reflect.ProxyGenerator.checkReturnTypes(ProxyGenerator.java:332) at java.base/java.lang.reflect.ProxyGenerator.generateClassFile(ProxyGenerator.java:467) at java.base/java.lang.reflect.ProxyGenerator.generateProxyClass(ProxyGenerator.java:211) at java.base/java.lang.reflect.Proxy$ProxyBuilder.defineProxyClass(Proxy.java:469)

Expected behavior

I would expect the named native query to be created successfully, as it is with the baseline profile, or at least I would like to understand whether this is a known incompatibility in Spring's SharedEntityManager integration/proxying for the current Hibernate 8 / Jakarta Persistence 4.0 API shape.

Notes

This reproducer currently focuses only on this named native query case because it is the first failing scenario I was able to isolate clearly. If useful, I can extend it with additional query variants to verify whether the issue is broader than this specific case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions