Re: datanucleus.query.resultSizeMethod of "COUNT" is only valid for use with JDOQL or JPQL currently


mayank.chawla@...
 

Hello,

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,

JDODQQuery.java
 finally
        {
            mconn.release();
        }
 

public void managedConnectionPreClose()
                                {
                                    if (!ec.getTransaction().isActive())
                                    {
                                        // Non-Tx : disconnect query from ManagedConnection (read in unread rows etc)
                                        qr1.disconnect();
                                    }
                                }
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.

ScrollableQueryResult.java
        public boolean hasNext()
        {
            synchronized (ScrollableQueryResult.this)
            {
                if (!isOpen())
                {
                    // Spec 14.6.7 Calling hasNext() on closed Query will return false
                    return false;
                }
 
                int theSize = size();
                if (applyRangeChecks)
                {
                    if (theSize < query.getRangeToExcl()-query.getRangeFromIncl())
                    {
                        // Size reached before upper limit of range
                        return iterRowNum <= (query.getRangeFromIncl() + theSize - 1);
                    }
 
                    if (iterRowNum == query.getRangeToExcl()-1)
                    {
                        endIndex = iterRowNum;
                    }
                    // When we are at "query.getRangeToExcl()-1" we have 1 more element
                    return (iterRowNum <= (query.getRangeToExcl()-1));
                }
 
                // When we are at at "size()-1" we have one more element
                return (iterRowNum <= (theSize - 1));
            }
        }
,
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.

Join main@datanucleus.groups.io to automatically receive all group messages.