13 Replies Latest reply on Jul 26, 2002 12:56 PM by leela

    jbosscmp-jdbc.xml, ejb-jar.xml for cmr

    Steve Knight Newbie

      Can someone post these files for a simple CMR example.
      I can't seem to get the relation to load properly.

      I would like to compare mine to known working versions to see what I am doing wrong.

      Thanks!

      Steve

        • 1. Re: jbosscmp-jdbc.xml, ejb-jar.xml for cmr
          Abe Zafar Newbie

          You are not alone. I haven't been able to get CMR working either. Considering there are no "working" examples out there, not even in the package that they sell you, I am starting to suspect that CMR simply does not work.

          • 2. Re: jbosscmp-jdbc.xml, ejb-jar.xml for cmr
            Lance Cranford Newbie

            I have a one-to-many unidirectional relationship between Order and Line Items defined.

            Here's my ejb-jar.xml relation section:

            <!-- Relationships -->

            <ejb-relation >
            <ejb-relation-name>Order-LineItems</ejb-relation-name>
            <!-- unidirectional -->
            <ejb-relationship-role >
            <ejb-relationship-role-name>one-Order-has-many-LineItems</ejb-relationship-role-name>
            One
            <relationship-role-source >
            <ejb-name>Order</ejb-name>
            </relationship-role-source>
            <cmr-field >
            <cmr-field-name>lineItems</cmr-field-name>
            <cmr-field-type>java.util.Collection</cmr-field-type>
            </cmr-field>
            </ejb-relationship-role>
            <ejb-relationship-role >
            <ejb-relationship-role-name>one-LineItem-belongs-to-one-Order</ejb-relationship-role-name>
            Many
            <cascade-delete/>
            <relationship-role-source >
            <ejb-name>LineItem</ejb-name>
            </relationship-role-source>
            </ejb-relationship-role>
            </ejb-relation>




            Here's my jbosscmp-jdbc.xml relationship section:


            <ejb-relation>
            <ejb-relation-name>Order-LineItems</ejb-relation-name>
            <relation-table-mapping>
            <table-name>tb_order_lineItems</table-name>
            </relation-table-mapping>
            <ejb-relationship-role>
            <ejb-relationship-role-name>one-Order-has-many-LineItems</ejb-relationship-role-name>
            <key-fields>
            <key-field>
            <field-name>id</field-name>
            <column-name>order_id</column-name>
            </key-field>
            </key-fields>
            </ejb-relationship-role>
            <ejb-relationship-role>
            <ejb-relationship-role-name>one-LineItem-belongs-to-one-Order</ejb-relationship-role-name>
            <key-fields>
            <key-field>
            <field-name>id</field-name>
            <column-name>line_item_id</column-name>
            </key-field>
            </key-fields>
            </ejb-relationship-role>
            </ejb-relation>


            This is simply creates a tb_Order_LineItems link table with two foriegn key references to the Order and LineItems table.

            • 3. Re: jbosscmp-jdbc.xml, ejb-jar.xml for cmr
              Abe Zafar Newbie

              Do you have a One-to-One Unidirectional working example of xml docs. I do have a One-to-many unidirectional working, but not a One-to-One.

              Thanks,

              • 4. Re: jbosscmp-jdbc.xml, ejb-jar.xml for cmr
                Abe Zafar Newbie

                I just noticed that your example jbosscmp-jdbc.xml example containts fields that do not exist in the examples that are contained with the cmp doc that jboss sells. This is what I have, any ideas which one is the right one? Notice the foreign key tag in my example. JBoss people it would help immensely if you add working examples with your distributions. Thank you.

                <ejb-relation>
                <ejb-relation-name>User-License</ejb-relation-name>
                <foreign-key-mapping>
                <ejb-relationship-role>
                <ejb-relationship-role-name>user-has-license</ejb-relationship-role-name>

                <foreign-key-fields>
                <foreign-key-field>
                <field-name>id</field-name>
                <column-name>license_id</column-name>
                </foreign-key-field>
                </foreign-key-fields>

                </ejb-relationship-role>

                <ejb-relationship-role>
                <ejb-relationship-role-name>license-belongsto-user</ejb-relationship-role-name>

                <foreign-key-fields/>

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

                • 5. Re: jbosscmp-jdbc.xml, ejb-jar.xml for cmr
                  Abe Zafar Newbie

                  Disregard my previous question regarding the discrepncy in the xml examples. There isn't a discrepency, you are using relation-mapping, I am using forein key. So I guess foreing key mapping is not working for me. Do you have a One to One unidirectional foreing key mapping relation?

                  Thanks again.

                  • 6. Re: jbosscmp-jdbc.xml, ejb-jar.xml for cmr
                    Dain Sundstrom Master

                    > <foreign-key-fields>
                    > <foreign-key-field>
                    > <field-name>id</field-name>
                    > <column-name>license_id</column-name>
                    > </foreign-key-field>
                    > </foreign-key-fields>

                    This is not the way mappings are specifiec anymore. Take a look at the jbosscmp-jdbc_3_0.dtd file in the docs/dtd directory of the JBoss distribution for details.

                    • 7. Re: jbosscmp-jdbc.xml, ejb-jar.xml for cmr
                      Abe Zafar Newbie

                      Thank you all for your suggestions, but none of the suggestions proved to be helpful. Again after your suggestions here are the two xml excerpts. The suprising thing is that it does not matter if I put anything in the jbossscmp-jdbc.xml file, I still get the same error. I do know what I put in the ejb-jar.xml file is correct because I have checked that against the ejb2.0 specs.

                      This is the exception: The License table has only 2 columns: id and licenseNumber, but for some reason the mapping thinks it has to put a foreign key to the user table as the third column. I have already moved around the key from the one relation tag to the other one without any success.

                      22:59:40,916 ERROR [entity/License] Could not create entity
                      java.sql.SQLException: Unexpected token: / in statement [INSERT INTO LICENSE (id, license_number, entity/User_license) VALUES
                      at org.hsqldb.Trace.getError(Trace.java:180)
                      at org.hsqldb.Result.(Result.java:175)
                      at org.hsqldb.jdbcConnection.executeHSQL(jdbcConnection.java:907)
                      at org.hsqldb.jdbcConnection.execute(jdbcConnection.java:718)

                      ejb-jar excerpt:

                      <ejb-relation>
                      <ejb-relation-name>User-License</ejb-relation-name>
                      <ejb-relationship-role>
                      <ejb-relationship-role-name>user-has-license</ejb-relationship-role-name>
                      One
                      <relationship-role-source>
                      <ejb-name>entity/User</ejb-name>
                      </relationship-role-source>
                      <cmr-field>
                      <cmr-field-name>license</cmr-field-name>
                      </cmr-field>
                      </ejb-relationship-role>
                      <ejb-relationship-role>
                      <ejb-relationship-role-name>license-belongsto-user</ejb-relationship-role-name>
                      One
                      <relationship-role-source>
                      <ejb-name>entity/License</ejb-name>
                      </relationship-role-source>
                      </ejb-relationship-role>
                      </ejb-relation>


                      jbosscmp-jdbc.xml exerpt:

                      <ejb-relation>
                      <ejb-relation-name>User-License</ejb-relation-name>
                      <foreign-key-mapping>
                      <ejb-relationship-role>
                      <ejb-relationship-role-name>user-has-license</ejb-relationship-role-name>
                      <key-fields>
                      <key-field>
                      <field-name>id</field-name>
                      <column-name>license_id</column-name>
                      </key-field>
                      </key-fields>
                      </ejb-relationship-role>

                      <ejb-relationship-role>
                      <ejb-relationship-role-name>license-belongsto-user</ejb-relationship-role-name>
                      <key-fields/>
                      </ejb-relationship-role>
                      </foreign-key-mapping>
                      </ejb-relation>


                      Again if this clue helps: Even when I remove the relation from the jbosscmp file I still get the same error so it's telling me that somehow it is not interpreting the ejb-jar.xml file properly.

                      Thank you, I hope after these insights into the problem I get to a solution or at least some JBoss guy coming out and saying "yeah I know that's a problem."

                      • 8. Re: jbosscmp-jdbc.xml, ejb-jar.xml for cmr
                        Dain Sundstrom Master

                        You have the keys on the wrong side. Switch the sides and it should work. You are still thinking in the backwards foreign key logic.

                        • 9. Re: jbosscmp-jdbc.xml, ejb-jar.xml for cmr
                          Travel Maniac Newbie

                          I tried the relationship mapping without using foreign key, and this time no weird made-up column was used in the SQL. But when I tried to do a getUsers() from Group (where a group has many users), I get this error:

                          Exception in thread "main" java.lang.reflect.UndeclaredThrowableException: java.io.NotSerializableException: org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet

                          Did I forget to flag something in some xml?

                          Thanks
                          G

                          • 10. Re: jbosscmp-jdbc.xml, ejb-jar.xml for cmr
                            Dain Sundstrom Master

                            CMR collections (RelationSet) are defiantely not serializable. They are not allowed to be serialized by the EJB spec. You are also not allowed to expose a CMR collection over a remote interface.

                            • 11. Re: jbosscmp-jdbc.xml, ejb-jar.xml for cmr
                              Travel Maniac Newbie

                              OK, but how did I manage to expose that class to the remote interface? I mean, I didn't hardcode anything of that sort, so I must have forgotten or inadvertently placed some field in either jbosscmp-jdbc.xml or ejb-jar.xml. Would you know what that missing or added field(s) might be?

                              Here's my jboscmp-jdbc.xml, the relationship bit:


                              <ejb-relation>
                              <ejb-relation-name>Group-Users</ejb-relation-name>
                              <relation-table-mapping>
                              <table-name>vector_user</table-name>
                              </relation-table-mapping>
                              <ejb-relationship-role>
                              <ejb-relationship-role-name>
                              group-contains-users
                              </ejb-relationship-role-name>
                              <key-fields>
                              <key-field>
                              <field-name>identifier</field-name>
                              <column-name>group_id</column-name>
                              </key-field>
                              </key-fields>
                              </ejb-relationship-role>
                              <ejb-relationship-role>
                              <ejb-relationship-role-name>
                              user-belongsto-group
                              </ejb-relationship-role-name>
                              <key-fields>
                              <key-field>
                              <field-name>uid</field-name>
                              <column-name>user_id</column-name>
                              </key-field>
                              </key-fields>
                              </ejb-relationship-role>
                              </ejb-relation>

                              </jbosscmp-jdbc>

                              • 12. Re: jbosscmp-jdbc.xml, ejb-jar.xml for cmr
                                Dain Sundstrom Master

                                This has nothing to do with XML. You are trying to get a CMR collection from the remote interface and you can only access a CMR collection from a local interface.

                                • 13. org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet
                                  leela Newbie

                                  i have a similar situation here. i have getUsers() in the Group Entity Local Interface.

                                  How shoudl i test that function outside the JVM,as I dont have access to LocalObject and It is not exposed to Remote.

                                  Do i need to test it with only Session bean Inside that JVM which has access to its Local Object.

                                  Thanks in advance.
                                  Leela