-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to use result set streaming on version 1.6.3 with Hibernate #1393
Comments
Steaming was only released in 1.6.2. Are you sure that under 1.6.0 you were actually streaming the results? |
Well, it was calling TypedQuery.getResultStream() and was working to return a Stream of EntityViews. |
We wrap TypedQuery in a custom implementation that would do the entity view wrapping, so I am assuming just the default stream implementation was used prior (which falls back on calling getResultList().stream()) |
Interesting that you use this in a JHipster application. Maybe you want to help us with a sample application here? #332 To me, this looks like an issue with the Hibernate session management. It seems you are closing the Hibernate session at some point, before you are done with scrolling/streaming. Before 1.6.2 the result was fully fetched eagerly, so that's why you didn't have problems so far. I don't know enough about JHipster unfortunately to help you with this, but you need to keep the Hibernate session open until the request finishes. |
Maybe you can open a Hibernate session explicitly and add a close handler to the result stream via |
That's interesting... I'll have to look into how sessions are managed with WebFlux and @async |
I think this was part of the issue. I'm now opening my own EntityManager in the service and passing it along, then closing when the Stream closes, but now I'm getting this: java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class com.visotrust.viso.service.riskinsight.SlimRiskAssessment ([Ljava.lang.Object; is in module java.base of loader 'bootstrap'; com.visotrust.viso.service.riskinsight.SlimRiskAssessment is in unnamed module of loader 'app') This is when my flatMap() is trying to accumulate the SlimRiskAssessment objects coming from the stream, but instead of getting an EntityView SlimRiskAssessment I'm getting an Object[] of the values that should go into it. |
Ahh, now this is an actual issue with Blaze-Persistence, although I am a bit surprised as the transformation should happen as you can see in https://github.com/Blazebit/blaze-persistence/blob/master/core/impl/src/main/java/com/blazebit/persistence/impl/query/ObjectBuilderTypedQuery.java#L80 Could you maybe try to debug to help us understand what is going on? |
Can you point me to where I should drop a breakpoint? I'm building a Flux from the stream returned from query.getResultStream() like this: private Flux getRiskAssessmentsFlux(@NotNull Long orgId, Optional<List> maybeDrIds, EntityManager em) { and then passing that flux directly into a flatmap which is where it's failing. |
How does |
ObjectBuilderTypedQuery.getResultStream() is called. The objectBuilder objectInstantiator has the correct constructor for the Impl class built for my EntityView |
`public Stream getRisks(@NotNull Long senderOrgId, Optional<List> maybeDrIds, EntityManager em) {
|
I think it's this in the ChainingObjectBuilder: It's just returning the Object[] without transforming it |
Ok, so I guess that the delegate |
Okay, gotcha. I guess we were living without it before. Thanks for taking a look. |
…ith entity views containing no collections
…ing to allow streaming
…ith entity views containing no collections
…ing to allow streaming
Description
Using the above snippet works on version 1.6.0, but since moving to 1.6.3 (this is required on our end), we receive the following exception.
The temporary workaround provided by @jwgmeligmeyling worked, which is great, but we are relying on streaming here because these result sets are large.
Here is a screenshot of the call stack:

Looks like it is delegating down to hibernate's QueryImpl on 1.6.3.
Expected behavior
This exception does not occur and we get a stream of results, just as we did on 1.6.0
Actual behavior
Hibernate exception thrown -
org.hibernate.exception.GenericJDBCException: could not advance using next()
Steps to reproduce
I have created this test project - https://github.com/dsarlo-viso/blaze-web-implementation-issues - but I am unable to reproduce the issue here. Looking to get some insight in this thread into what could have possibly changed between 1.6.0 and 1.6.3 that this is now a problem for us.
Environment
Version: 1.6.3
JPA-Provider: Hibernate 5.4.29.Final (Spring Data JPA 2.4.4)
DBMS: PostgreSQL 9.6
Application Server: Spring Boot 2.4.4
The text was updated successfully, but these errors were encountered: