1 Reply Latest reply on Jan 30, 2003 3:39 PM by madsmart

    dynamic-ql for many-to-many relationship

    dare2d4l

      Hi all:

      I have two beans:
      Activity : ID (primary)
      forOrderID (many-to-many cmr field)
      Order: ID (primary)
      forActivityID (many-to-many cmr field)

      They have a many-to-many relationship between them using foreign-table mapping. When I execute a query using dynamic-ql like so:

      String filter = "";
      String orderBy = "";

      String jbossQL = "SELECT DISTINCT OBJECT(o) FROM activity AS o, IN (o.forOrderID) AS r WHERE r.iD = " + getID() + filter + orderBy;

      (returns all activites belonging to order where the order id = ID)

      I get an error:

      javax.ejb.FinderException: Error compiling ejbql: org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "o.forOrderID" at line 1, column 85.
      Was excepting: <COLLECTION_VALUED_PATH> ...


      When i do a similar query in a one-to-many relatioship, the query works. Why doesn't the query work in a many-to-many relationship?

      Thanks!
      Eddie


        • 1. Re: dynamic-ql for many-to-many relationship
          madsmart

          Hi,

          I have a similar problem

          Two beans, this is my relation:

          <ejb-relation-name>NavigationTree-Areas</ejb-relation-name>
          <ejb-relationship-role>
          <ejb-relationship-role-name>NavigationTree</ejb-relationship-role-name>
          Many
          <cascade-delete/>
          <relationship-role-source>
          <ejb-name>NavigationTree</ejb-name>
          </relationship-role-source>
          <cmr-field>
          <cmr-field-name>areaId</cmr-field-name>
          </cmr-field>
          </ejb-relationship-role>
          <ejb-relationship-role>
          <ejb-relationship-role-name>AreaId</ejb-relationship-role-name>
          One
          <relationship-role-source>
          <ejb-name>Areas</ejb-name>
          </relationship-role-source>
          <cmr-field>
          <cmr-field-name>navigationTree</cmr-field-name>
          <cmr-field-type>java.util.Collection</cmr-field-type>
          </cmr-field>
          </ejb-relationship-role>
          </ejb-relation>

          and this is my query:


          <query-method>
          <method-name>findAllNavigationTreeByAreaAndLanguage</method-name>
          <method-params>
          <method-param>java.lang.Integer</method-param>
          <method-param>java.lang.Integer</method-param>
          </method-params>
          </query-method>
          <ejb-ql>SELECT Object(o) FROM NavigationTree AS o, IN (o.areaId) as t, IN (o.languageId) as r WHERE t.areaId = ?1 AND r.languageId = ?2</ejb-ql>


          and I get an error:

          org.jboss.deployment.DeploymentException: Error compiling ejbql; - nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "o.areaId" atline 1, column 50.
          Was expecting:
          <COLLECTION_VALUED_PATH>...

          Why doesn't the query don´t work? can you help me?

          Regards.

          MAD