7 Replies Latest reply on Mar 22, 2004 10:18 AM by beal91

    Load relation failed 1-Many relationship

    zommick

      I’ve been using JBoss for about 6 months; however, I’m just starting to use CMP 2.0 in the new JBoss 3 - production version. I’m having problems trying to create a 1 to Many relationship. I have the CMP documentation which I purchased; however, it seems that it is not up to date in regards to defining foreign keys.



      I have an EJB called unarchiveRequest which has many archiveRecordings in it. The unarchiveRequest has a primary key of integer. However, the archiveRecordings has a composite key. I haven’t seen any examples of a 1 to many relationship with a composite key.


      I get the following error when I try to get the archiveRecordings from the unarchiveRequest object. The weird thing is that no fields are being displayed in the SELECT clause. Do you have any idea why that is?



      java.rmi.ServerException: Cannot retrieve 'java:comp/env/ejb/rcats/UnarchiveRequest': original message = 'javax.transaction.TransactionRolledbackException: Load relation failed

      Embedded Exception

      Unexpected token: FROM in statement [SELECT FROM archive_recording WHERE (request_id=1)]; nested exception is:

      javax.ejb.EJBException: Load relation failed





      Thanks very much!

      Jordan Zommick

        • 1. Re: Load relation failed 1-Many relationship
          dsundstrom

          When did you purchase you documentation? If you purchased it before June of this year, you will need to buy the new updated documentation at flashline. If you purchased a subscription, then you can download the update from FlashLine.

          • 2. Re: Load relation failed 1-Many relationship
            zommick

            Other than obtaining the latest docs, do you know why its giving me that error?

            • 3. Re: Load relation failed 1-Many relationship
              dsundstrom

              The select clause is missing columns. This is usually caused by a misconfigured ejb-jar.xml file such as missing an prim-key-field element or a bad custom primary key. Another common cause trying to use unknown primary keys which are not currently supported.

              • 4. Re: Load relation failed 1-Many relationship
                zommick

                This is taken from my ejb-jar.xml . I have a prim-key-field defined for the unarchive request bean; however, the archive recording bean has a composite key so it just has primary class defined. What do you think?


                <display-name>Unarchive Request Record</display-name>
                <ejb-name>UnarchiveRequest</ejb-name>
                com.radical.telephony.status.ejb.UnarchiveRequestHome
                com.radical.telephony.status.ejb.UnarchiveRequest
                <ejb-class>com.radical.telephony.status.ejb.UnarchiveRequestBean</ejb-class>
                <persistence-type>Container</persistence-type>
                <prim-key-class>java.lang.Integer</prim-key-class>
                False
                <cmp-version>2.x</cmp-version>
                <abstract-schema-name>UnarchiveRequest</abstract-schema-name>
                <cmp-field><field-name>requestId</field-name></cmp-field>
                <cmp-field><field-name>requestTime</field-name></cmp-field>
                <cmp-field><field-name>userName</field-name></cmp-field>
                <cmp-field><field-name>status</field-name></cmp-field>
                <primkey-field>requestId</primkey-field>
                <resource-ref>
                RCATSPool Data Source
                <res-ref-name>java:/RCATSPool</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
                </resource-ref>
                <ejb-local-ref>
                Archive Recording Record Home
                <ejb-ref-name>ejb/rcats/ArchiveRecording</ejb-ref-name>
                <ejb-ref-type>Entity</ejb-ref-type>
                <ejb-link>ArchiveRecording</ejb-link>
                <local-home>com.radical.telephony.status.ejb.ArchiveRecordingHomeLocal</local-home>
                com.radical.telephony.status.ejb.ArchiveRecordingLocal
                </ejb-local-ref>
                <ejb-ref>
                Archive Manager Bean Home
                <ejb-ref-name>ejb/rcats/ArchiveManagerBean</ejb-ref-name>
                <ejb-ref-type>Session</ejb-ref-type>
                <ejb-link>ArchiveManagerBean</ejb-link>
                com.radical.telephony.status.ejb.ArchiveManagerHome
                com.radical.telephony.status.ejb.ArchiveManager
                </ejb-ref>

                EJBQL to find all UnarchiveRequests
                <query-method>
                <method-name>findAllRequests</method-name>
                <method-params />
                </query-method>
                <ejb-ql>Select OBJECT(a) From UnarchiveRequest a</ejb-ql>





                <display-name>Archive Recording Record</display-name>
                <ejb-name>ArchiveRecording</ejb-name>
                com.radical.telephony.status.ejb.ArchiveRecordingHome
                com.radical.telephony.status.ejb.ArchiveRecording
                <local-home>com.radical.telephony.status.ejb.ArchiveRecordingHomeLocal</local-home>
                com.radical.telephony.status.ejb.ArchiveRecordingLocal
                <ejb-class>com.radical.telephony.status.ejb.ArchiveRecordingBean</ejb-class>
                <persistence-type>Container</persistence-type>
                <prim-key-class>com.radical.telephony.status.ejb.ArchiveRecordingPK</prim-key-class>
                False
                <cmp-version>2.x</cmp-version>
                <abstract-schema-name>ArchiveRecording</abstract-schema-name>
                <cmp-field><field-name>systemId</field-name></cmp-field>
                <cmp-field><field-name>stationId</field-name></cmp-field>
                <cmp-field><field-name>timeStamp</field-name></cmp-field>
                <cmp-field><field-name>mediaName</field-name></cmp-field>
                <cmp-field><field-name>archiveNumber</field-name></cmp-field>
                <cmp-field><field-name>status</field-name></cmp-field>
                <resource-ref>
                RCATSPool Data Source
                <res-ref-name>java:/RCATSPool</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
                </resource-ref>




                <ejb-relation>
                <ejb-relation-name>Request-Recording</ejb-relation-name>
                <ejb-relationship-role>
                <ejb-relationship-role-name>unarchiveRequest-has-many-recordings</ejb-relationship-role-name>
                <relationship-role-source>
                <ejb-name>UnarchiveRequest</ejb-name>
                </relationship-role-source>
                One
                <cmr-field>
                <cmr-field-name>recordingList</cmr-field-name>
                <cmr-field-type>java.util.Collection</cmr-field-type>
                </cmr-field>
                </ejb-relationship-role>
                <ejb-relationship-role>
                <ejb-relationship-role-name>recording-belongsto-unarchiveRequest</ejb-relationship-role-name>
                <relationship-role-source>
                <ejb-name>ArchiveRecording</ejb-name>
                </relationship-role-source>
                Many
                <cascade-delete/>
                </ejb-relationship-role>
                </ejb-relation>

                • 5. Re: Load relation failed 1-Many relationship
                  dsundstrom

                  Then my guess is the custom primary key class is coded incorrectly (custom PKs are difficult to code correctly).

                  • 6. Re: Load relation failed 1-Many relationship

                    I often forget to make the fields public in my primary key class. That mistake also exhibits causes this problem. Gets, and setter, but the fields too must be public (though, I can't imaging why).

                    • 7. Re: Load relation failed 1-Many relationship
                      beal91

                      This is according to the specification:

                      Section 10.8.2:

                      The primary key class must be public, and must have a public constructor with no parameters.

                      All fields in the primary key class must be declared as public.

                      The names of the fields in the primary key class must be a subset of the names of the container-managed fields. (This allows the container to extract the primary key fields from an instance's container-managed fields, and vice versa.)

                      Jeff Beal