SELECT DISTINCT class cast exception
bwallis42 Dec 18, 2012 8:08 PMShould the following query work? (running modeshape 3.0.1.Final, JDK 1.6.0_37)
{code}
QueryManager queryManager = session.getWorkspace().getQueryManager();
ValueFactory vf = session.getValueFactory();
Query query = queryManager.createQuery(
"SELECT DISTINCT p.* FROM [inf:patient] AS p JOIN [inf:section] AS s ON ISCHILDNODE(s, p) where s.[inf:name] <> $sectionname",
Query.JCR_SQL2);
query.bindValue("sectionname", vf.createValue(sectionName));
QueryResult r = query.execute();
{code}
I get a class cast exception when the query is executed (below).
If I run it without the DISTINCT it works but the join will return duplicate nodes as there are two inf:section child nodes for every inf:patient node.
{code}
java.lang.ClassCastException: java.lang.String cannot be cast to org.modeshape.jcr.query.QueryResults$Location
at org.modeshape.jcr.query.process.DistinctComponent.execute(DistinctComponent.java:56)
at org.modeshape.jcr.query.process.QueryProcessor.execute(QueryProcessor.java:96)
at org.modeshape.jcr.query.process.QueryEngine.execute(QueryEngine.java:140)
at org.modeshape.jcr.query.lucene.LuceneQueryEngine$1.getResults(LuceneQueryEngine.java:151)
at org.modeshape.jcr.query.JcrQuery.execute(JcrQuery.java:119)
at au.com.infomedix.cpf4.ds.PatientRecordOperations.addSectionToPatients(PatientRecordOperations.java:165)
at au.com.infomedix.cpf4.ds.TestPatientRecordOperations.testAddSectionToPatients(TestPatientRecordOperations.java:106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
{code}
Looking at the code where the error occurs, it is getting a String where it is expecting a location. The string is the value of one of the node properties. There are QueryResult$Location instances in the array but not at the index contained in firstLocationIndex.
thanks.