1 2 Previous Next 16 Replies Latest reply on Jul 28, 2002 1:40 AM by Dain Sundstrom

    still no luck with CMR foreign key

    Travel Maniac Newbie

      So here are the relations fields of ejb-jar.xml and jboss.xml. Just as another user had noted, when I tried Group.getUsers() I get this sql in the log, and since the column Group_users doesn't exist (I don't know how JBoss came up with that guess!), a SQL exception is thrown.

      This is a 1:N relationship unidirectional so only Group can retrieve a list of users and not user retrieving Group.

      ejb-jar.xml:

      <ejb-relation>
      <ejb-relation-name>Group-Users</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>
      group-contains-users
      </ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Group</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>users</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>
      user-belongsto-group
      </ejb-relationship-role-name>
      Many
      <cascade-delete/>
      <relationship-role-source>
      <ejb-name>User</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>


      jbosscmp-jdbc.xml:

      <ejb-relation>
      <ejb-relation-name>Group-Users</ejb-relation-name>
      <foreign-key-mapping>
      <ejb-relationship-role>
      <ejb-relationship-role-name>group-contai
      ns-users</ejb-relationship-role-name>
      <foreign-key-fields/>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>user-belongsto-group</ejb-relationship-role-name>
      <foreign-key-fields>
      <foreign-key-field>
      <field-name>identifier</
      field-name>
      <column-name>group_id</column-name>
      </foreign-key-field>
      </foreign-key-fields>
      </ejb-relationship-role>
      </foreign-key-mapping>
      </ejb-relation>

      </jbosscmp-jdbc>

      Thanks for the help. I wish there were a comprehensive example out there. I wonder if such exists in the docs, but I want to wait till JBoss 3.0 doc comes out.

      Later.
      G

        • 1. Re: still no luck with CMR foreign key
          Abe Zafar Newbie

          Man, you are not alone. I have the same exact problem: JBoss assumes that there is a column in my table. Don't get your hopes high for the docs either, I bought the docs and none of those examples there work either. I really believe this thing is not working, and I urge who ever that says it is working provide us with an example that does, so far I haven't seen one.

          • 2. Re: still no luck with CMR foreign key
            Travel Maniac Newbie

            Hmm, this is a bit frustrating; I thought they solved it for you, but apparently not. Yes, we definitely need some examples, be it with the distribution or part of the paid documentation. All I would need is some testing suite JBoss developers use to see how they did it. Since I am not one of the developers, I don't know how big a deal this is. It's better to see the entire set of classes and all the xml files. I suspect that our problem lies outside the "relations" tags of both xml files.

            G

            • 3. Re: still no luck with CMR foreign key
              Dain Sundstrom Master

              > Don't get your hopes high for the docs either,
              > I bought the docs and none of those examples there
              > work either. I really believe this thing is not
              > working, and I urge who ever that says it is working
              > provide us with an example that does, so far I
              > haven't seen one.

              All of the examples included with the JBoss documentation work perfectly. Flashline has a bug in it's software where it can send you an old copy of the documentation. Send flashline an email and you will get the new documentation.

              CMRs work perfectly. To prove this let jboss create the tables for you. Unless you named on of your EJBs of field a SQL reserved word (a very bad idea) the application will deploy and run perfectly.

              • 4. Re: still no luck with CMR foreign key
                Travel Maniac Newbie

                Hmm, so I thought, based on dsundstrom's message, that mine didn't work because my ejb name was Group. So I renamed it to UserGroup in every place. I still get the same error (except that the column is now UserGroup_users instead of just Group_users....)

                So the docs that you are all talking about is for JBoss3.0?

                G

                • 5. Re: still no luck with CMR foreign key
                  Abe Zafar Newbie

                  Yes the docs that I am talking about is for jboss 3.0 cmp. Unfortunately they seem to be outdated.

                  • 7. Re: still no luck with CMR foreign key
                    Travel Maniac Newbie

                    Hmm, well, abezafar, see if you can get an updated one and tell me if the examples there work.

                    Thanks!
                    G

                    • 8. Re: still no luck with CMR foreign key
                      Ljubisa Kovacevic Newbie

                      I also wasn't "lucky" enough in one case.

                      The only thing i couldn't make it work was "unidirectional", otherwise CMR behaves quite good.

                      Now, Dan I don't know if I'm missing something, I downloaded WorkBook a few months ago and was able to deploy my EJBs long time ago, and let container to do the "magic". From the start I wasn't able to get rid of "bidirectional" relationships in the case of "1:1" relationship.

                      So in the case of the example from JBoss CMP-Docs I always get aditional field in MySQL USER table:

                      CustomerBean_userLocal referencing customer table


                      downloaded examples:
                      ---------------------- ejb-jar--------------
                      <!--
                      ONE-TO-ONE unidirectional relationship:
                      User is unaware of Customer
                      -->
                      <ejb-relation>
                      <ejb-relation-name>Customer-User</ejb-relation-name>
                      <ejb-relationship-role>
                      <ejb-relationship-role-name>customer-is-a-user</ejb-relationship-role-name>
                      One
                      <relationship-role-source>
                      <ejb-name>CustomerEJB</ejb-name>
                      </relationship-role-source>
                      <cmr-field>
                      <cmr-field-name>userLocal</cmr-field-name>
                      </cmr-field>
                      </ejb-relationship-role>
                      <ejb-relationship-role>
                      <ejb-relationship-role-name>user-for-customer</ejb-relationship-role-name>
                      One
                      <relationship-role-source>
                      <ejb-name>UserEJB</ejb-name>
                      </relationship-role-source>
                      </ejb-relationship-role>
                      </ejb-relation>



                      ---------------

                      ---------------jbosscmp-jdbc------------
                      <ejb-relation>
                      <ejb-relation-name>Customer-User</ejb-relation-name>
                      <foreign-key-mapping>
                      <ejb-relationship-role>
                      <ejb-relationship-role-name>customer-is-a-user</ejb-relationship-role-name>

                      <foreign-key-fields>
                      <foreign-key-field>
                      <field-name>userId</field-name>
                      <column-name>USER_ID</column-name>
                      </foreign-key-field>
                      </foreign-key-fields>

                      </ejb-relationship-role>

                      <ejb-relationship-role>
                      <ejb-relationship-role-name>user-for-customer</ejb-relationship-role-name>

                      <foreign-key-fields/>

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


                      How can I stop container to produce this aditional column. Is Documentation 2 months old good enough for JBOSS RC2 (I'm using) or I'm doing something wrong?

                      • 9. Re: still no luck with CMR foreign key
                        Dain Sundstrom Master

                        You need to upgrade to atleast JBoss 3.0. There have been a lot of bugs fixed since then. There is also new version of the documentation. The xml you are using for your jbosscmp-jdbc.xml file is very old. Check out the new dtd in the docs/dtd directory of the JBoss distribution.

                        • 10. Re: still no luck with CMR foreign key
                          Ljubisa Kovacevic Newbie

                          Thanks Dan,

                          I will as soon as I get some time, actually I'm using JBoss 3.0 RC2 and it's very stable, disregarding this issue. I wasted half day and couldn't get it working (unidirectionally), so I added adittional column in one of the tables, to get the App working.

                          Two question for you:

                          1. So is this issue solved (getting rid of bidir. refs) , do you get unidirectional 1:1 with latest workBook examples, and

                          2. Do I have to purchase Docs again (I did it two or three months ago) to downloaded newest version.



                          • 11. Re: still no luck with CMR foreign key
                            Dain Sundstrom Master

                            > Thanks Dan,

                            My name is Dain.

                            > 1. So is this issue solved (getting rid of bidir.
                            > refs) , do you get unidirectional 1:1 with latest
                            > workBook examples, and

                            Yes. Gangster-Hangout

                            > 2. Do I have to purchase Docs again (I did it two or
                            > three months ago) to downloaded newest version.

                            Yes, free upgrades only come with the subscriptions.

                            • 12. Re: still no luck with CMR foreign key
                              Ljubisa Kovacevic Newbie

                              Thanks Dain,

                              You are the Ma(i)n!


                              (After all, you deserve some money for your hard work.)

                              • 13. Re: still no luck with CMR foreign key
                                Sreekanth Newbie

                                Dain,

                                So is it true to say that we cannot have a foreign key as part of a primary key in the child table of a parent-child relationship? For example, let's say we have two tables, Organization and Personnel. Organization's have organization_id as PK and Personnel have organization_id and employee_id as PKs (assume that employee_id may not be unique due to company mergers so that we cannot just make employee_id as PK).

                                Since organization_id is part of the PK for Personnel, we have to declare it as a CMP field. But to define the 1-N relationship between Organization and Personnel, we need to declare organization_id as a <key-field> in the relationship. When an insert is performed with a new Personnel, it looks like the SQL generated duplicates an additonal organization_id? Is this correct or are we not mapping the relationship correctly?

                                Thanks,
                                Sreekanth

                                • 14. Re: still no luck with CMR foreign key
                                  Dain Sundstrom Master

                                  You can not have a foreign key a part of a primay key.

                                  1 2 Previous Next