Description
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 anIllegalArgumentException.
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 testRun the Hibernate 8 / JPA 4.0 profile:
mvn test -Ph8-jpa4Observed 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.
Activity
Adapt query proxy if necessary (for compatibility with Hibernate 8.0)
jhoeller commentedon Jun 9, 2026
This turned out to be a problem with overlapping methods in various Hibernate Query interfaces, declaring a covariant return type for method chaining: specifically,
MutationOrSelectionQueryandNativeQueryboth declare the same methods with a different covariant return type that is only fully resolved inNativeMutationOrSelectionQueryImpl- which we cannot proxy since it is a concrete class rather than an interface. Unfortunately we cannot proxy the combination of interfaces either if some such covariant return type is not fully resolved in any of them.As a solution, we fall back to the declared Query interface from the EntityManager method return type for a start - and if any other Query type is needed on
asStatementorunwrapcalls, we dynamically adapt the query proxy to the expected query interface type (effectively creating a new proxy with the same InvocationHandler but a different proxy interface).Fixed for 7.0.9 (where we aim for initial runtime compatibility with Hibernate 8.0 pre-releases) as well as 7.1.0-M1 (where we aim for complete JPA 4.0 programming model support).
oscarfanchin commentedon Jun 11, 2026
Hi, I tested my local Spring Data build, and all the tests are green. Thanks.
marvin-hm commentedon Aug 24, 2026
Hi @jhoeller,
we're facing an issue which seems to be related to this change. We're creating a stored procedure and getting the exception
As far as I can see, the issue is related to the change of this issue, within the method
Object invoke(Object proxy, Method method, @Nullable Object[] args) throws Throwable. It seems like the else-if block which checks forregisterStoredProcedureParameteris never reached, when calling the methodStoredProcedureQuery registerStoredProcedureParameter(int position, Class<?> type, ParameterMode mode);from a proxy created viaentityManager.createStoredProcedureQuery(procedureName);. That leads to a map of outputParameters which is never filled and to the exception.I haven't found any related issue so far and we've just updated from Spring Boot 4.1.0 to 4.1.1 (spring-orm 7.0.8 -> 7.0.9). Could you check that, please?
Thanks and BR
Marvin
sbrannen commentedon Aug 24, 2026
Hi @marvin-hm,
Since this issue is closed and 7.0.9 has already been released, if you think you have encountered a regression, please create a new issue with the details and a small application (or test class) which reproduces the issue -- preferably something we can download and run such as a sample app or test in a public Git repository or ZIP file.
Thanks
Add missing proxy hints for Hibernate 8's MutationOrSelectionQuery