hibernate-reactive icon indicating copy to clipboard operation
hibernate-reactive copied to clipboard

Make the illegal pop message more user friendly

Open DavideD opened this issue 2 years ago • 17 comments

Users can sometime see this error:

org.hibernate.HibernateException: java.util.concurrent.CompletionException: java.lang.IllegalStateException: Illegal pop() with non-matching JdbcValuesSourceProcessingState

Usually, when they are sharing the session in different streams. We could add some info to the error message.

DavideD avatar Apr 21 '23 09:04 DavideD

Hibernate ORM is generating this error. I've created an issue for it: https://hibernate.atlassian.net/browse/HHH-16869

DavideD avatar Jun 29 '23 08:06 DavideD

Hi were you able to find any workaround related to this issue?

prashantguleria avatar Jul 06 '23 06:07 prashantguleria

What do you mean? This error means that the session is not used correctly. The user needs to change something.

This issue refers only to the error message

DavideD avatar Jul 06 '23 08:07 DavideD

Ohh Alright, I have started getting this exception intermittently when using hibernate 6.2.2. I am still unable to find how it's happening because it's occurring once in > 1000 executions.

prashantguleria avatar Jul 06 '23 10:07 prashantguleria

It happens when the same session instance is used in parallel by different threads or different CompletionStage or Uni.

DavideD avatar Jul 06 '23 11:07 DavideD

Well... I guess it could also be a bug. In any case we would need to see some code to be able to help. Feel free to create a separate issue with more details.

DavideD avatar Jul 06 '23 11:07 DavideD

Well... I guess it could also be a bug. In any case we would need to see some code to be able to help. Feel free to create a separate issue with more details.

Hi I have created this issue.

https://hibernate.atlassian.net/browse/HHH-16903

Can you please have a look into it?

prashantguleria avatar Jul 06 '23 12:07 prashantguleria

I've run into this error as well. Reproduces on my system(Using Mutiny.SessionFactory):

final var result = sessionFactory
        .withTransaction(session -> {
             Uni.combine()
                        .all()
                        .unis(session.find(Item1.class, id),  session.find(Item2.class, id2))
                        .asTuple();
            }).await().indefinitely();

I know that this is a perfect example of what NOT to do in Hibernate Reactive 😊, but the error message could be a lot friendlier.

noobgramming avatar Oct 26 '23 15:10 noobgramming

This is an error thrown by Hibernate ORM. I've opened an issue some time ago about it: https://hibernate.atlassian.net/browse/HHH-16869

In short, this is not the only situation where this message is thrown and this is the best that can be done at the moment. I'm going to close this issue, eventually we might be able to solve the issue by not having to throw the error in the first place.

DavideD avatar Oct 30 '23 15:10 DavideD

happend to me while using parallel streams... when i tested allone everything worked well.... but then there were two testers at the same time ^^

wutzebaer avatar Oct 30 '23 22:10 wutzebaer

I had this case: using 6.2.18.Final

entity X.getY() relates OneToOne to entity Y Y has a String property z with a setter that throws exception of you Y.setZ(null) The database happened to have Y's with z=null

Then "SELECT x from X x" fails with this "illegal pop() with non-matching JdbcValuesSourceProcessingState"

The actual problem (that setZ throwed some Exception) was not logged or present in the stacktrace at all.

So it appears, then hibernate n+1-loads the Y's after having loaded a list of X'es, when calling X.setZ(null) throws exception, this exception gets swallowed, and eventually "illegal pop() with non-matching JdbcValuesSourceProcessingState" is thrown instead.

dcaillia avatar Jan 16 '24 12:01 dcaillia

I you could provide a test case I can have a look at it. Does it also happen with the latest Hibernate Reactive (2.2.1.Final) with Hibernate ORM 6.4.1.Final?

DavideD avatar Jan 16 '24 13:01 DavideD

For other users who are upgrading to Hibernate 6 and facing this issue, the below hint from @DavideD was a great time saver for us.

It happens when the same session instance is used in parallel by different threads or different CompletionStage or Uni.

We were indeed using the same session concurrently by using Flux.merge, which did not raise any exceptions with Hibernate 5. Changing to a sequential subscriber like Flux.concat fixed it.

Our Hibernate version is 6.2.13.Final.

The exception message is a bit cryptic, so I hope this is helpful for other users.

mcanalesmayo avatar Feb 28 '24 13:02 mcanalesmayo

I spent hours trying to debug an issue caused by this. Changing the error message would definitely help future developers.

Sothatsit avatar Feb 29 '24 18:02 Sothatsit

I'm leaving this here for future people who may have this problem. In my case I was using parallelStream and getting this error, I see that in the documentation https://hibernate.org/reactive/documentation/2.4/reference/html_single/#_sessions_and_vert_x_contexts this is specified "The Hibernate session is not thread-safe (nor "stream-safe"), ..."

Gabun avatar Jun 12 '25 09:06 Gabun

@DavideD Hibernate ORM has a way to customize the exception converter. I wonder if we could use that to "augment" the error message, since it's clear that lots of people are struggling with this.

gavinking avatar Jun 12 '25 09:06 gavinking

I will have a look.

DavideD avatar Jun 12 '25 09:06 DavideD