7 Replies Latest reply on Jan 16, 2003 7:01 PM by lorensrosen

    Multi-part primary key - How?

    cobraflow

      Hi,

      I have spent a couple of days trying to do a simple(ish) one to many relationship. All examples that I have seen use a single unique key field in the child table.

      I have two tables (all String columns) :-

      T1
      id
      name

      T2
      id
      ref
      description

      I have a primary key class (T2PK) containing 'id' and 'ref' (id + ref = unique). In my T2EJB I have an ejbCreate(String id, String ref). I create T2EJB's from inside T1EJB calling the create above.

      Could someone please describe/point me in the direction of some docs explaining how to setup ejb-jar.xml and jbosscmp-jdbc.xml to do this? I have tried with varying degrees of success to get it done.

      P.S. I found that switching log4j to debug for 'org.jboss.ejb.plugins.cmp.jdbc' tells me when/if I'm getting close!


      Thanks

      Lewis

        • 1. Re: Multi-part primary key - How?
          alexb

          Lewis,

          I've posted the same quetion and it was never answered so I hope someone will answer your post...

          I'm starting to think that jboss dosen't support this switch dosen't make any sense...


          Alex

          • 2. Re: Multi-part primary key - How?
            cobraflow

            This has got to be the...second... most simple relationship going!

            We need the id column to be both cmp and cmr. If I build the thing with, what I would class as the logical configuration, the only error I get is that the child bean generates an insert statement with the id column occurring twice. If this is 'supposed' to work, I could easily patch the code to look for duplicated column names. I have looked all over for docs on this. The spec does not cover it at all (As it seems to be down to the implementer to supply this part).

            Lewis

            • 3. Re: Multi-part primary key - How?
              erik777

              I have posted the same problem from a different perspective at

              http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ there seems to be a problem when a foreign key is part of a primary key. When it is not part of the primary key, I can get around the duplicate column problem by commenting out the individual abstract foreign key get/sets and CMP field definitions. But, this doesn't work when it's part of the primary key, because it needs to select these columns.

              I hope we find an answer. This is a show stopper for me. I really don't want to redesign the database just to get around a bug, particularly when I need backward compatibility with a working and in production 2.4 version.

              • 4. Re: Multi-part primary key - How?
                tolborg

                I would also like an answer to these questions.

                • 5. Re: Multi-part primary key - How?
                  lorensrosen

                  Given that work has started on version 4, I would guess a backport of this feature to version 2 is unlikely.

                  I can see one really ugly possible workaround. It would involve adding some new tables and possibly some triggers, so it's not worth persuing unless you can do that to your production database and are getting desperate for workarounds.

                  • 6. Re: Multi-part primary key - How?
                    tolborg

                    So .. its a "fact" that using CMR fields as a part of the primary key in EJBs is not possible in the latest stable version of JBoss?

                    • 7. Re: Multi-part primary key - How?
                      lorensrosen

                      There are others who can speak more authoritatively but my understanding is that a fix for this is in 3.2, which is currently at Release Candidate status.