About I use hibernate multithreaded queries simultaneously happened: "Illegal pop () with non - matching JdbcValuesSourceProcessingState" exception #38151
-
Describe the bug我有个任务是需要从数据库中一次性查询多张不同的表,由于数据量比较大这个任务比较耗时,因此我想到使用多线程来分同时查询不同的表以此来减少任务执行时间。 I have a task that needs to query multiple different tables from the database at one time. Due to the large amount of data, this task is time-consuming, so I think of using multiple threads to query different tables simultaneously to reduce the task execution time. Expected behavior顺序完成查询任务 Actual behavior抛出了异常:Illegal pop() with non-matching JdbcValuesSourceProcessingState java.util.concurrent.CompletionException: java.lang.IllegalStateException: Illegal pop() with non-matching JdbcValuesSourceProcessingState
Caused by: java.lang.IllegalStateException: Illegal pop() with non-matching JdbcValuesSourceProcessingState How to Reproduce?提供一个简单的示例,就模拟多线程并发查询的情况。 Provides a simple example to simulate the situation of multi-threaded concurrent queries.
Output of
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Please don't use bug reports to ask questions. This is what discussions are for. You cannot use the same session from multiple threads, and there's no way around that. Just open a separate transaction in each thread, and that will lead to using a separate session in each thread, and all will be fine. With Hibernate ORM/JPA you'd do this (won't work for you):
With Hibernate Reactive I'm sure there's a similar solution, but I don't personally know what it is. I think it has its own way to open transactions. |
Beta Was this translation helpful? Give feedback.
-
Also, unrelated to your problem but pagination doesn't seem like a good way to iterate over a large dataset; I'd personally use scrolling instead. But then Panache doesn't expose that, so you'd need to use plain Hibernate code. And I don't know how Hibernate Reactive exposes scrolling (if it even does). |
Beta Was this translation helpful? Give feedback.
Also, unrelated to your problem but pagination doesn't seem like a good way to iterate over a large dataset; I'd personally use scrolling instead. But then Panache doesn't expose that, so you'd need to use plain Hibernate code. And I don't know how Hibernate Reactive exposes scrolling (if it even does).