5 Replies Latest reply on Aug 6, 2002 1:55 PM by Dain Sundstrom

    Problem with EJB-QL parsing

    Joe Simone Newbie

      I am using JBoss 3.0 final and as far as I can tell it has been working quite well with IBM's DB2.

      Now it seems I have a ejb-ql problem that I don't quite understand.

      I have a collection hierarchy as follows:

      Event -> Program -> Track -> Course -> Session

      each of these entities has a 1-to-many CMR relationship with the next one down the hierarchy. I can go up and down using the pks to navigate the CMR collections no problem.

      However if I try to make a finder with the following ejb-ql:

      SELECT OBJECT(s) FROM Event AS e WHERE e.id = ?1,
      IN (e.programs) AS p,
      IN (p.tracks) AS t,
      IN (t.courses) AS c,
      IN (c.sessions) AS s

      I get the following error:

      org.jboss.deployment.DeploymentException: Error compiling ejbql; - nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "s" at line 1, column 16.
      Was expecting:
      <IDENTIFICATION_VARIABLE> ...
      )

      I am assuming my ejb-ql statement has the correct syntax, but that something gets confused in the parsing.

      Also, each bean has a collection CMR for the next one down called, programs, tracks, courses, and sessions.

      s is identified by the end of the statement and should be returned as OBJECT(s). According to the Kangaroo book, this should work. No?

      Can anyone shed any light on this issue?

      Many thanks,
      joe

        • 1. Re: Problem with EJB-QL parsing
          Dain Sundstrom Master

          You have:

          SELECT OBJECT(s) FROM Event AS e WHERE e.id = ?1,
          IN (e.programs) AS p,
          IN (p.tracks) AS t,
          IN (t.courses) AS c,
          IN (c.sessions) AS s

          Try this:

          SELECT OBJECT(s)
          FROM
          Event AS e,
          IN (e.programs) AS p,
          IN (p.tracks) AS t,
          IN (t.courses) AS c,
          IN (c.sessions) AS s
          WHERE e.id = ?1

          • 2. Re: Problem with EJB-QL parsing
            Joe Simone Newbie

            Thanks!
            I get a clean deployment now!

            BUT, if I call the query on the EventLocalHome interface, where its defined as:

            public Collection findSessions(String eventId)
            throws FinderException;

            With the following method :

            public ArrayList listSessionsByEvent(String eventId) {
            Collection sessions = null;
            ArrayList empty = new ArrayList();
            try {
            sessions = eventLocalHome.findSessions(eventId);
            }
            catch (Exception ex) {
            throw new EJBException(ex.getMessage());
            }
            System.out.println(sessions.size()+" **************");
            Iterator i = sessions.iterator();
            while (i.hasNext()) {
            SessionLocal session= (SessionLocal) i.next();
            System.out.println(session.getPrimaryKey()+" ******");
            }
            return empty;
            }


            I get 81 as the number of objects returned, which correct. BUT I don't get SessionLocals beans back! In fact, I get an exception on the getPrimaryKey() -- so these returned objects are not bean references??

            I am confused as to what is actually coming back from the query now.

            Thanks for help in advance!
            It is much appreciated.

            joe

            P.S. If I grab the query from server.log - the last line before the exception, which represents the EJB-QL and issue it against the DB as a SQL query I do get 81 primary keys returned.

            • 3. Re: Problem with EJB-QL parsing
              Joe Simone Newbie

              Oops! I found my problem. I was expecting a collection of sessions from my EventLocal interface. I put the query in the SessionLocal entity and the query works perfectly now.

              Thanks for your help Dain.

              regards,
              joe

              • 4. Re: Problem with EJB-QL parsing
                leela Newbie

                i have the same situation here . I could get everything inot collection but at the same time they are not interfaces iam gettign

                iam getting collection of strings like "someCMR field:Id" like "emsLocal:1023"
                How did u manage to get the Local Remote Interfaces etc.


                I tried moving the query to the down level ., It is getting the collection, but it doesnot solely contain either the remoteInterface or PrimaryKey. but it contains some Cmr field followed by :Primary Key.

                Do we need to parse for key and again regenerate REmote Interface..
                ur response is appreciated/

                Thanks
                Leela

                • 5. Re: Problem with EJB-QL parsing
                  Dain Sundstrom Master

                  Finders on the RemoteHome return a collection of Remote entities and finders on the LocalHome return a collection of Local entities. If you want remote entities call the finder on the remote home.