We're updating the issue view to help you get more done. 

Cannot count distinct results when multiple select clauses are present

Description

From a 2.1 error report:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 org.openvpms.component.business.service.archetype.ArchetypeServiceException: Failed to execute query: ArchetypeQuery[firstResult=0,maxResults=0,count=true,constraints=ShortNameConstraint[constraints={NodeConstraint[alias=patient,nodeName=name,operator=EQ,parameters={k*}],ObjectSelectConstraint[alias=patient,nodeName=<null>],ObjectSelectConstraint[alias=customer,nodeName=<null>],CollectionNodeConstraint[archetypeConstraint=ShortNameConstraint[constraints={CollectionNodeConstraint[archetypeConstraint=ArchetypeConstraint[constraints={},alias=customer,state=BOTH,primaryOnly=false]]},alias=rel,state=BOTH,primaryOnly=false,shortNames={entityRelationship.patientOwner}]],NodeSortConstraint[alias=customer,ascending=true,nodeName=name],NodeSortConstraint[alias=customer,ascending=true,nodeName=id],NodeSortConstraint[alias=patient,ascending=true,nodeName=name],NodeSortConstraint[alias=patient,ascending=true,nodeName=id],NodeSortConstraint[alias=patient,ascending=true,nodeName=id]},alias=patient,state=ACTIVE,primaryOnly=true,shortNames={party.patientpet}]]. at org.openvpms.component.business.service.archetype.ArchetypeService.get(ArchetypeService.java:374) at sun.reflect.GeneratedMethodAccessor193.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:68) at org.openvpms.component.business.service.security.OpenVPMSMethodSecurityInterceptor.invoke(OpenVPMSMethodSecurityInterceptor.java:50) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) at com.sun.proxy.$Proxy55.get(Unknown Source) at org.openvpms.component.business.service.archetype.DelegatingArchetypeService.get(DelegatingArchetypeService.java:301) at org.openvpms.web.component.im.query.AbstractArchetypeServiceResultSet.countResults(AbstractArchetypeServiceResultSet.java:278) at org.openvpms.web.component.im.query.AbstractCachingResultSet.getResults(AbstractCachingResultSet.java:103) at org.openvpms.web.component.im.query.AbstractResultSet.getPages(AbstractResultSet.java:322) at org.openvpms.web.component.im.query.AbstractResultSet.getPages(AbstractResultSet.java:104) at org.openvpms.web.component.im.table.PagedIMTableModel.getPages(PagedIMTableModel.java:166) at org.openvpms.web.echo.table.TableNavigator.getLastPage(TableNavigator.java:422) at org.openvpms.web.echo.table.TableNavigator.last(TableNavigator.java:168) at org.openvpms.web.echo.table.TableNavigator$5.onAction(TableNavigator.java:325) at org.openvpms.web.echo.event.ActionListener.actionPerformed(ActionListener.java:40) at nextapp.echo2.app.button.AbstractButton.fireActionPerformed(AbstractButton.java:135) at echopointng.ButtonEx$1.actionPerformed(ButtonEx.java:120) at nextapp.echo2.app.button.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:70) at echopointng.model.DefaultButtonModelEx.doAction(DefaultButtonModelEx.java:51) at echopointng.ButtonEx.processInput(ButtonEx.java:202) at nextapp.echo2.app.update.ClientUpdateManager.process(ClientUpdateManager.java:116) at nextapp.echo2.app.update.UpdateManager.processClientUpdates(UpdateManager.java:89) at nextapp.echo2.webcontainer.ContainerSynchronizeService.renderUpdate(ContainerSynchronizeService.java:471) at nextapp.echo2.webrender.service.SynchronizeService.service(SynchronizeService.java:279) at nextapp.echo2.webrender.WebRenderServlet.process(WebRenderServlet.java:273) at org.openvpms.web.echo.servlet.SpringWebContainerServlet.processRequest(SpringWebContainerServlet.java:234) at org.openvpms.web.echo.servlet.SpringWebContainerServlet.process(SpringWebContainerServlet.java:173) at nextapp.echo2.webrender.WebRenderServlet.doPost(WebRenderServlet.java:189) at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.openvpms.web.echo.servlet.Log4JMDCUserFilter.doFilter(Log4JMDCUserFilter.java:58) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:316) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:205) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:610) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: org.openvpms.component.business.dao.im.common.IMObjectDAOException: Failed to execute the query: select distinct patient, customer from org.openvpms.component.business.dao.hibernate.im.party.PartyDO as patient left outer join patient.targetEntityRelationships as rel with (rel.archetypeId.shortName = :shortName1) left outer join rel.source as customer with customer.archetypeId.shortName = :shortName2 where (patient.archetypeId.shortName = :shortName0 and patient.active = :active0 and patient.name like :name0) order by customer.name asc, customer.id asc, patient.name asc, patient.id asc, patient.id asc. at org.openvpms.component.business.dao.hibernate.im.IMObjectDAOHibernate$DefaultQueryDelegator.get(IMObjectDAOHibernate.java:1020) at org.openvpms.component.business.dao.hibernate.im.IMObjectDAOHibernate$DefaultQueryDelegator.get(IMObjectDAOHibernate.java:1003) at org.openvpms.component.business.dao.hibernate.im.IMObjectDAOHibernate$QueryDelegator.get(IMObjectDAOHibernate.java:964) at org.openvpms.component.business.dao.hibernate.im.IMObjectDAOHibernate.get(IMObjectDAOHibernate.java:207) at org.openvpms.component.business.dao.hibernate.im.IMObjectDAOHibernate$$FastClassBySpringCGLIB$$69c8dab2.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653) at org.openvpms.component.business.dao.hibernate.im.IMObjectDAOHibernate$$EnhancerBySpringCGLIB$$63692524.get(<generated>) at org.openvpms.component.business.service.archetype.ArchetypeService.get(ArchetypeService.java:371) ... 91 more Caused by: org.openvpms.component.business.dao.hibernate.im.query.QueryBuilderException: Cannot count distinct results when multiple select clauses are present at org.openvpms.component.business.dao.hibernate.im.query.QueryContext.getQueryString(QueryContext.java:200) at org.openvpms.component.business.dao.hibernate.im.IMObjectDAOHibernate$DefaultQueryDelegator.get(IMObjectDAOHibernate.java:1015) ... 105 more

Environment

None

Status

Assignee

Tim Anderson

Reporter

Tim Anderson

Labels

None

Components

Fix versions

Affects versions

2.1

Priority

Minor