6 Replies Latest reply on Jul 15, 2003 7:58 AM by aloubyansky

    JDO query

    tuan08

      Hi

      I write a very simple POJO and use jboss-aop, JBossDO to intercept some method call and save the POJO. There is no problem with this . But When I try to query the POJO , the PersistenceManager always return an empty Collection and on the second query , I got the exception below. Does anyone have idea What do I miss. Thank for your input.

      PersistenceManager pm = factory.getPersistentManager() ;
      Query q = pm.newQuery(POJO.class, "name='" + objectName + "'");
      q.compile();
      Collection result = (Collection)q.execute();
      System.out.println("result size = " + result.size());
      pm.close();



      00:11:43,639 ERROR [STDERR] javax.jdo.JDOFatalInternalException: Could not create an instance of PersistenceCapable: exo.content.persistent.POJO
      00:11:43,639 ERROR [STDERR] at org.jboss.persistence.jbossdo.util.JBossJDOHelper.newInstanceForClass(JBossJDOHelper.java:46)
      00:11:43,639 ERROR [STDERR] at org.jboss.persistence.jbossdo.util.JBossJDOHelper.newInstanceForClass(JBossJDOHelper.java:53)
      00:11:43,639 ERROR [STDERR] at org.jboss.persistence.jbossdo.JBossPersistenceManagerInternal.getObjectById(JBossPersistenceManagerInternal.java:350)
      00:11:43,639 ERROR [STDERR] at org.jboss.persistence.jbossdo.JBossQuery.execute(JBossQuery.java:144)
      00:11:43,639 ERROR [STDERR] at exo.content.aop.interceptor.PersistentInterceptor$GetNodeByUri.execute(PersistentInterceptor.java:121)
      00:11:43,639 ERROR [STDERR] at exo.content.aop.interceptor.PersistentInterceptor.invoke(PersistentInterceptor.java:59)

        • 1. Re: JDO query
          mcorey

          I can't speak for the exception you're getting, but I believe the reason you're not getting any results from the query is because the equality comparison should take the form of a normal java expression -- that is, you should use '==' instead of '='... you're correct in that the single quotes are needed now to surround the string instead of double quotes (or \", actually), but I've submitted a patch to allow the double quotes, so hopefully that will be integrated in an upcoming release.

          Should the use of '=' should throw an exception, since it's not actually a valid query, or are there times when a single equals sign is allowable that I'm not thinking of?

          m

          • 2. Re: JDO query
            tuan08

            JBossDO DR2 uses =,|,& <>

            Warning: if you download DR2 binaries from sf.net, be aware, that there are bugs in JDOQL implementation, i.e. instead of &&, ||, == and != it uses &, |, = and <> correspondingly. This is fixed in CVS version.

            • 3. Re: JDO query
              aloubyansky

              The problem is: Could not create an instance of PersistenceCapable: exo.content.persistent.POJO.

              At the moment, I use Class.newInstance() (it'll be changed soon).

              There could be two problems:
              1. can you create an instance of the class with newInstance()?
              2. if 1 is ok, then the class is not properly inhanced. I see you use some aop, maybe there are some clashes? How do you deploy?

              alex

              • 4. Re: JDO query
                tuan08

                Hi loubyansky ,

                Thank for your reply. I cannot use (POJO.class).newInstance() in my interceptor. Probably that is the problem. I also wonder what happen to a serialized POJO . I check your code and I see you use AOP to introduce JBossPersistentCapable interface

                14:56:56,340 INFO [STDOUT] request uri = /home
                14:56:56,350 ERROR [STDERR] java.lang.InstantiationException: exo.content.persis
                tent.POJO
                14:56:56,370 ERROR [STDERR] at java.lang.Class.newInstance0(Class.java:293)
                14:56:56,380 ERROR [STDERR] at java.lang.Class.newInstance(Class.java:261)
                14:56:56,390 ERROR [STDERR] at exo.content.aop.interceptor.PersistentInterce
                ptor$GetNodeByUri.execute(PersistentInterceptor.java:123)
                14:56:56,410 ERROR [STDERR] at exo.content.aop.interceptor.PersistentInterce
                ptor.invoke(PersistentInterceptor.java:62)
                14:56:56,430 ERROR [STDERR] at org.jboss.aop.Invocation.invokeNext(Invocatio
                n.java:61)
                14:56:56,450 ERROR [STDERR] at exo.content.aop.interceptor.CacheInterceptor.
                invoke(CacheInterceptor.java:57)
                14:56:56,470 ERROR [STDERR] at org.jboss.aop.Invocation.invokeNext(Invocatio
                n.java:61)
                14:56:56,490 ERROR [STDERR] at org.jboss.aop.ClassAdvisor.invokeMethod(Class
                Advisor.java:729)
                14:56:56,510 ERROR [STDERR] at org.jboss.aop.ClassAdvisor.invokeMethod(Class

                • 5. Re: JDO query
                  tuan08

                  I forget to say that I have method save in POJO class and it is just an empty method . I use interceptor to intercept that method :-)

                  • 6. Re: JDO query
                    aloubyansky

                    > I cannot use (POJO.class).newInstance() in my
                    > interceptor.

                    You need to fix this problem with newInstance to work with JBossDO. As I mentioned, I'll get rid of using newInstance soon but at the moment it works this way.

                    > I check your code and I see you use AOP to
                    > introduce JBossPersistentCapable interface

                    Yes, the classes are enhanced at deployment time. I am working on making the enhancement closer to the JDO spec.

                    alex