8 Replies Latest reply on May 18, 2009 5:30 PM by alwu-Oracle

    Query Error in Jena adaptor

    691732
      I'm wrapping an instance of the ModelOracleSem class from the Jena adaptor in an OntModel, a Jena class used to access OWL concepts stored in an RDF model. I'm getting an exception trying to list individuals in the model, and the underlying cause appears to be a ClassCastException within the Oracle-Jena adaptor.

      My code:

      GraphOracleSem graph = new GraphOracleSem(oracle, "TEST_MODEL");
      ModelOracleSem model = new ModelOracleSem(graph);
      OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model);
      ExtendedIterator iter = ontModel.listIndividuals();
      try {
      while (iter.hasNext()) System.out.println(iter.next());
      } finally {
      iter.close();
      }

      The exception:
      Exception in thread "main" java.lang.ClassCastException: com.hp.hpl.jena.graph.Node_Variable cannot be cast to com.hp.hpl.jena.sparql.core.Var
           at oracle.spatial.rdf.client.jena.OracleSemQueryPlan.convert(OracleSemQueryPlan.java:136)
           at oracle.spatial.rdf.client.jena.OracleSemQueryPlan.getVariables(OracleSemQueryPlan.java:159)
           at oracle.spatial.rdf.client.jena.OracleSemQueryPlan.executeBindings(OracleSemQueryPlan.java:179)
           at com.hp.hpl.jena.ontology.impl.OntModelImpl.queryFor(OntModelImpl.java:2562)
           at com.hp.hpl.jena.ontology.impl.OntModelImpl.listIndividuals(OntModelImpl.java:439)
           at com.revelytix.oracle.TestJena.main(TestJena.java:52)
        • 1. Re: Query Error in Jena adaptor
          alwu-Oracle
          Hmmm. Please email me the test data you used. I will see what is going on.

          Thanks,

          Zhe Wu
          • 2. Re: Query Error in Jena adaptor
            691732
            The error appears independent of the particular data that is loaded into the model. It seems to happen in the query planner before the model is actually accessed.

            For the record, though, I loaded my test model with the FOAF vocabulary.
            • 3. Re: Query Error in Jena adaptor
              alwu-Oracle
              OntModel and its related APIs have not been the focus of Jena Adaptor primarily because the inference mechanism (if selected) is quite different. Right now, you get Oracle's native inference support through the Attachment class. And the Attachment is used together with GraphOracleSem class.

              Back to this specific problem, I have already put in a fix that seems to solve this problem.

              Cheers,

              Zhe Wu
              • 4. Re: Query Error in Jena adaptor
                696067
                I am getting exactly the same problem, only without using Jena's OntologyModel, here is my code:

                Oracle oracle = new Oracle(url, user, password);
                GraphOracleSem graph;
                try{
                     graph = new GraphOracleSem(oracle, "owltst_model");
                }catch(SQLException e){...}
                ModelOracleSem model = new ModelOracleSem(graph);
                String queryString = "SELECT * "
                     + "WHERE { "
                     + " ?subject ?predicate ?object . "
                     + "} ";
                Query query = QueryFactory.create(queryString);
                QueryExecution qexec = QueryExecutionFactory.create(query, model);
                ResultSet results;
                try {
                     results = qexec.execSelect();
                     ResultSetFormatter.out(System.out, results, query);
                }

                I get the following error:
                -----
                Exception in thread "main" java.lang.ClassCastException: com.hp.hpl.jena.graph.Node_Variable
                     at oracle.spatial.rdf.client.jena.OracleSemQueryPlan.convert(OracleSemQueryPlan.java:136)
                     at oracle.spatial.rdf.client.jena.OracleSemQueryPlan.getVariables(OracleSemQueryPlan.java:159)
                     at oracle.spatial.rdf.client.jena.OracleSemQueryPlan.executeBindings(OracleSemQueryPlan.java:179)
                     at com.hp.hpl.jena.query.engine1.QueryIterBasePattern$StageBasePattern.<init>(QueryIterBasePattern.java:84)
                     at com.hp.hpl.jena.query.engine1.QueryIterBasePattern.nextStage(QueryIterBasePattern.java:51)
                     at com.hp.hpl.jena.query.engine1.QueryIterRepeatApply.makeNextStage(QueryIterRepeatApply.java:90)
                     at com.hp.hpl.jena.query.engine1.QueryIterRepeatApply.hasNextBinding(QueryIterRepeatApply.java:51)
                     at com.hp.hpl.jena.query.engine.QueryIteratorBase.hasNext(QueryIteratorBase.java:91)
                     at com.hp.hpl.jena.query.engine.ResultSetStream.hasNext(ResultSetStream.java:65)
                     at com.hp.hpl.jena.query.resultset.ResultSetMem.<init>(ResultSetMem.java:83)
                     at com.hp.hpl.jena.query.resultset.TextOutput.write(TextOutput.java:131)
                     at com.hp.hpl.jena.query.resultset.TextOutput.write(TextOutput.java:114)
                     at com.hp.hpl.jena.query.resultset.TextOutput.write(TextOutput.java:102)
                     at com.hp.hpl.jena.query.resultset.TextOutput.format(TextOutput.java:49)
                     at com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:57)
                     at com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:45)
                     at OracleMain.main(OracleMain.java:113)
                -----

                What am I doing wrong?
                • 5. Re: Query Error in Jena adaptor
                  alwu-Oracle
                  I tried your code and I could not reproduce it. I got some output like the following.

                  ----------------------------------------------------------------------------------------------------------------------------------
                  | subject | predicate | object |
                  ==================================================================================================================================
                  | <http://www.example.com/test2> | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | <http://www.w3.org/2002/07/owl#Ontology> |
                  | <http://www.example.com/test1/> | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | <http://www.w3.org/2002/07/owl#Ontology> |
                  ----------------------------------------------------------------------------------------------------------------------------------

                  Can you try your code with an empty model? BTW, for this kind of query, you may want to try the
                  GraphOracleSem.find(Triple.ANY).
                  • 6. Re: Query Error in Jena adaptor
                    696067
                    Hum, this could be a version and/or configuration issue.
                    I tried using sdordfclient.jar Jena Adapter Release 2 (and also Release 1) with Jena 2.5.4 and also Jena 2.5.6, all four times I got the ClassCastException above.

                    Also, it's possible I made a installation error, I to install Semantic Web into the DB I did the following....
                    I installed Oracle 11.1.0.7 and followed [these instructions|http://www.oracle.com/technology/tech/semantic_technologies/documentation/jenadrv_patch_ig.txt] creating the SEM_TS database and then I did this:
                    -----
                    SQL> EXECUTE sem_apis.create_sem_model('owltst_model','owltst','triple');
                    PL/SQL procedure successfully completed.
                    SQL> INSERT INTO owltst VALUES (1, sdo_rdf_triple_s('owltst_model','http://foo.com/name/John', 'http://www.w3.org/2002/07/owl#sameAs','http://foo.com/name/JohnQ'));
                    1 row created.
                    SQL> commit;
                    SQL> EXECUTE sem_apis.create_entailment('owltst_idx',sem_models('owltst'), sem_rulebases('OWLPRIME'));
                    -----

                    Then I decided to install the 7600122 patch and following the instructions here, I did this:
                    -----
                    1) sqlplus MDSYS/<password>
                    @sdordfa.sql
                    @sdordfxh.sql
                    @sdordfh.sql
                    @sdordfai.plb
                    @sdordfxb.plb
                    @sdordfb.plb
                    @sdordfm.plb
                    @sdoseminfb.plb
                    @sdosemopib.plb
                    @sdosemvalb.plb
                    2) $ORACLE_HOME/bin/loadjava -u MDSYS/<password> -resolve -force -synonym -schema MDSYS -grant PUBLIC sdordf.jar
                    3)sqlplus MDSYS/<password>
                    exec sem_apis.adjust_views_for_vm;
                    -----
                    Is there anything I missed?

                    Note:
                    Also, one other thing I would like to add is that when I try to call ResultSetFormatter.out(System.out, results, query); (see the code above) using Jena 2.5.6 I get the following exception when the code is run:
                    -----
                    java.lang.VerifyError: (class: OracleMain, method: main signature: ([Ljava/lang/String;)V) Incompatible argument to function
                    Exception in thread "main"
                    -----

                    Edited by: user10960203 on Apr 14, 2009 2:32 PM

                    Edited by: user10960203 on Apr 14, 2009 2:40 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
                    • 7. Re: Query Error in Jena adaptor
                      alwu-Oracle
                      Why don't you send email to alan dot wu at oracle dot com. We can sort it out offline and post a summary later on.

                      Thanks,

                      Zhe Wu
                      • 8. Re: Query Error in Jena adaptor
                        alwu-Oracle
                        A quick summary of the problem.

                        The following error is actually caused by an incompatible version of pellet.jar (which automatically pulls in a set of jena libraries through the Class-Path setting in the MANIFEST.MF file).

                        java.lang.VerifyError: (class: OracleMain, method: main signature: ([Ljava/lang/String;)V) Incompatible argument to function

                        Cheers,

                        Zhe Wu