After further debugging we found - our application goes into Datanucleus layer twice in this flow. First time it creates query, execute it and return result. While returning the result, finally block of JQOQLQuery.java of performExecute() executes mconn.release(), which closes the connection and set query object to null in AbstractQueryResult.java(as ec.getTransaction().isActive() is false, query gets disconnected).
Please find below the code snippet,
So, in second flow when we go into Datanucleus layer by calling hasNext on returned object(it takes us to hasNext implementation of ScrollableQueryResult), there size() method takes us to AbstractQueryResult, where we get query object as null and exception is thrown.
I verified ec.getTransaction().isActive() was set to false in previous version(2.0.4) as well. Now, could you please let me know which property I need to set to have the behaviour where query is not set to null as we need to access it later.
I understand I am comparing with very old version, but I have to take reference to make it behave in similar manner. Thank you.