6 Replies Latest reply on Mar 24, 2004 4:32 PM by hergaty

    CMR - FK/PK issue

    steveridley

      Greetings,

      Has anyone managed to create a working example of CMR where the manager field is also the PK is the related table. I understand this is possible with 3.2.0RC1 but have not been able to succeed as yet. In fact upon deployment i am presented with:

      java.lang.ClassCastException: org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.resolveRelationship(JDBCCMRFieldBridge.java:296)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.resolveRelationships(JDBCEntityBridge.java:156)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.resolveRelationships(JDBCStoreManager.java:468)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:400)
      at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManager.java:198)


      I wonder if anyone could verify if they have succeeded with this issue and also was it a simple PK or were you able to succeed when the managed field was part of a compound PK.

      Thank you all in advance.

      Stephen.

        • 1. Re: CMR - FK/PK issue
          lafr

          This is the typical result of using remote interfaces for CMR.
          You must only use local interfaces for CMR !

          • 2. Re: CMR - FK/PK issue
            steveridley

            For those interested in this thread, I can confirm that with jboss3.2.0RC1, it is possible to have a foreign key as part of a simple or compound primary key !

            I have finally managed to create and test a working example with the help of the testsuite. The relationship cardinality was correctly observed as was a cascade delete. Nice. . .

            My ClassCast problem disappeared after reorganising jbosscmp-jdbc. Obviously I had got it wrong during previous attempts.

            Phew. . . . . . .

            Steve.

            • 3. Re: CMR - FK/PK issue
              sebastien_petrucci

              Hi,

              Could you please provide more explanations and samples ?

              Thx,
              Sebastien.

              • 4. Re: CMR - FK/PK issue
                ctrawick

                Yes please do. Specifically, I'm interested in the PK class.

                Here's what I've tried so far... I have a User bean that contains information about a user and I have a Tasks bean that contains information about certain tasks. In between them I have a UserTasks bean that maps the two plus contains other properties about the mapping. Its PK is the composite of the User bean's PK and the Task bean's PK:

                public class UserTaskPK {
                public UserPK user;
                public TaskPK task;

                // getters and setters
                }

                The UserTask bean has CMR fields user and task. All beans use local interfaces.

                This was my best guess for how to create the PK class, however when navigating to UserTask from User JBossCMP 3.2.0 generates an empty select clause:

                SELECT FROM UserTasks WHERE (userid=?)

                Historically, this has been because the CMP engine could not match fields from the PK class to the entity properties. I've also tried putting the UserPK and TaskPK fields themselves in the UserTaskPK to no avail.

                So, how do I structure the PK class so that composite PKs work?

                • 5. Re: CMR - FK/PK issue
                  steveridley

                  Yes of course,

                  I shall post a full working example tomorrow (is 10pm GMT) here and very tired !!!

                  Regards,
                  Steve.

                  • 6. Re: CMR - FK/PK issue
                    hergaty

                    Hi Steve,

                    can you still provide your example or do you know where I can have a look into one that explains the same problem?

                    Best Regards,
                    Thomas