2 Replies Latest reply on Sep 30, 2002 11:09 AM by mesketh

    Problem with 1-N relationship

    mesketh

      I have a problem with a fairly simple 1-N relationship. Here's the trace from my deploying to JBoss v3.0 over PostgreSQL 7.1.2:

      java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
      java.rmi.ServerException: Load relation failed
      Embedded Exception
      ERROR: Attribute 'workarea_roles' not found

      Can someone tell me what minor detail i'm missing here? I have declared getter/setters on the WorkArea bean only since i only 'CMR' that the Role-side of the relationship (wanting no backward pointing field to retrieve the WorkArea for a Role at this stage). I think i might be missing something to do with my bean declarations but, i can't see what (apologies for not including in mail).

      WorkArea(1) -> Role(N). The tables pre-exist complete with foreign key from the role to the work_area table based on the work_area_id (PK of the work_area table).

      Here's my DD (relationships section only):



      <!-- WorkArea has many Roles -->

      <ejb-relation>

      <ejb-relation-name>WorkArea-Role</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>workarea-has-roles</ejb-relationship-role-name>
      One
      <relationship-role-source><ejb-name>WorkArea</ejb-name></relationship-role-source>
      <cmr-field>
      <cmr-field-name>roles</cmr-field-name>
      <cmr-field-type>java.util.Set</cmr-field-type>
      </cmr-field>

      </ejb-relationship-role>

      <!-- Role belongs to a Work Area -->

      <ejb-relationship-role>
      <ejb-relationship-role-name>role-belongs-to-a-workarea</ejb-relationship-role-name>
      Many
      <relationship-role-source><ejb-name>Role</ejb-name></relationship-role-source>

      </ejb-relationship-role>
      </ejb-relation>


      Here's the jbosscmp-jdbc.xml:



      <ejb-relation>
      <ejb-relation-name>WorkArea-Role</ejb-relation-name>
      <foreign-key-mapping>

      <ejb-relationship-role>
      <ejb-relationship-role-name>workarea-has-roles</ejb-relationship-role-name>

      <foreign-key-fields/>

      </ejb-relationship-role>

      <ejb-relationship-role>
      <ejb-relationship-role-name>role-belongs-to-a-workarea</ejb-relationship-role-name>

      <foreign-key-fields>
      <foreign-key-field>
      <field-name>workAreaId</field-name>
      <column-name>WORK_AREA_ID</column-name>
      </foreign-key-field>
      </foreign-key-fields>

      <!--read-ahead>on-load</read-ahead-->

      </ejb-relationship-role>

      </foreign-key-mapping>
      </ejb-relation>






      thanks
      Mark

        • 1. Re: Problem with 1-N relationship
          tdang

          I think your mapping should look like this:


          <ejb-relation>
          <ejb-relation-name>WorkArea-Role</ejb-relation-name>
          <foreign-key-mapping>

          <ejb-relationship-role>
          <ejb-relationship-role-name>workarea-has-roles</ejb-relationship-role-name>

          <foreign-key-fields>
          <foreign-key-field>
          <field-name>workAreaId</field-name>
          <column-name>WORK_AREA_ID</column-name>
          </foreign-key-field>
          </foreign-key-fields>


          </ejb-relationship-role>

          <ejb-relationship-role>
          <ejb-relationship-role-name>role-belongs-to-a-workarea</ejb-relationship-role-name>

          <foreign-key-fields/><!--read-ahead>on-load</read-ahead-->

          </ejb-relationship-role>

          </foreign-key-mapping>
          </ejb-relation>



          Take a look in QuickStart, there is a very good example for relationships.

          By the way: I recommend you to use JBoss 3.0.1 for this purpose because JBoss 3.0 has a lot of bugs with relationships.

          Hope this help.

          • 2. Re: Problem with 1-N relationship
            mesketh

            Thanks for the reply. Yeah, i was rejigging it because it didn't work the other way (as the QS guide says it does). I get the same stack trace i.e.

            ---8<---

            java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
            java.rmi.ServerException: Load relation failed
            Embedded Exception
            ERROR: Attribute 'workarea_roles' not found

            ---8<---

            Do you know if i can check a log somewhere? i've checked the "logs" log files but, there's no sql in there. Do you know if Jboss is logging other priority messages which might contain any sql generated to it's log files? Postgres doesn't seem to be capturing it either. Any suggestions on that?

            Stop press: i've just changed <foreign-key-fields> to <key-fields> in both sections and the error has gone. Now i'm faced with a Serialization problem thus:

            java.lang.reflect.UndeclaredThrowableException: java.io.NotSerializableException: org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet

            at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:245)

            .. yadda...

            I think something on my Home/Remote i/f's isn't Serializable.

            Thanks again.

            Mark