title: Collections.sort() on Query list throws java.lang.UnsupportedOperationException: Query result sets are not modifiable
body: <p>I have this JDO service returning a <code>List&lt;Order&gt;</code>:</p>
  
  <pre><code>public List&lt;Order&gt; getOnGoingOrders() {
  
          List&lt;Order&gt; orderList = null;
          JDOPersistenceManager pm = (JDOPersistenceManager) persistenceManager.getPM();
  
          try {
  
              Query&lt;Order&gt; q = pm.newQuery(Order.class);
  
              q.setFilter("orderStatus != 'COMPLETED' &amp;&amp; orderStatus != 'CANCELLED'");
              q.setOrdering("orderPlacedTime desc");
  
              orderList = (List&lt;Order&gt;) q.execute();
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          return orderList;
      }
  </code></pre>
  
  <p>When the front end calls <code>Collections#sort()</code> on it, I get the below exception:</p>
  
  <pre><code> com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
  SEVERE: Error Rendering View[/index.xhtml]
  java.lang.UnsupportedOperationException: Query result sets are not modifiable
      at org.datanucleus.store.query.AbstractQueryResultIterator.set(AbstractQueryResultIterator.java:86)
      at java.util.List.sort(List.java:482)
      at java.util.Collections.sort(Collections.java:175)
      at org.primefaces.component.datatable.feature.SortFeature.singleSort(SortFeature.java:148)
      at org.primefaces.component.datatable.feature.SortFeature.encode(SortFeature.java:106)
      at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:80)
      at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:920)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
      at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:582)
      at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
      at org.primefaces.component.api.UIData.visitTree(UIData.java:827)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
      at javax.faces.component.UIForm.visitTree(UIForm.java:371)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
      at org.primefaces.component.api.UITabPanel.visitTree(UITabPanel.java:920)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
      at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403)
      at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:322)
      at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:57)
      at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:219)
      at org.omnifaces.context.OmniPartialViewContext.processPartial(OmniPartialViewContext.java:139)
      at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1004)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
      at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:432)
      at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134)
      at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
      at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
      at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
      at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
      at org.omnifaces.viewhandler.NoAutoGeneratedIdViewHandler.renderView(NoAutoGeneratedIdViewHandler.java:93)
      at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
      at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
      at org.apache.deltaspike.jsf.impl.listener.request.DeltaSpikeLifecycleWrapper.render(DeltaSpikeLifecycleWrapper.java:111)
      at javax.faces.lifecycle.LifecycleWrapper.render(LifecycleWrapper.java:92)
      at org.apache.deltaspike.jsf.impl.listener.request.JsfClientWindowAwareLifecycleWrapper.render(JsfClientWindowAwareLifecycleWrapper.java:160)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
      at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
      at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
      at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
      at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
      at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
      at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
      at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
      at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1517)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1474)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>How is this caused and how can I solve it?</p>