10 Replies Latest reply on Jan 27, 2003 6:42 PM by totolaricot

    CMR-Field also CMP-Field

    Frank Langelage Master

      JBoss-Head, JDK 1.4.1, Informix-DB
      Following given situation:
      Bean 1:
      Name=Festa, DBTable=festa, PK=festa_serial
      Bean 2:
      Name=Festr, DBTable=festr, PK=festa_serial+festr_pos_nr, FK=festa_serial -> festa
      Bean 3:
      Name=febdr, DBTable=febdr, PK=febdr_serial, FK=festa_serial -> festa

      As you can see, for bean 2 the CMR-Field festa_serial must be a CMP-Field, because it's part of the PK.
      For bean 3 the CMR-Field festa_serial must not be a CMP-Field. Otherwise you get a DeploymentException because of a "wrong" SQL-CreateTable-Statement.
      The field festa_serial is mentioned twice there.
      I would like JBoss to recognize that the CMR-Field is already there as a CMP-Field in both cases.

      So my question: Is this a Bug, a FeatureRequest or a must be which will not be changed ?

        • 1. Re: CMR-Field also CMP-Field
          Thomas Tolborg Newbie

          I second this question.

          • 2. Re: CMR-Field also CMP-Field
            ravidwivedi Newbie

            Hi Frank Langelage
            have you got any solution for the subject mentioned problem , because i am also facing the same problem?

            regards
            ravi

            • 3. Re: CMR-Field also CMP-Field
              Frank Langelage Master

              No ! I'm sorry.

              • 4. Re: CMR-Field also CMP-Field
                Scott Van Kirk Newbie

                I have also run into this and haven't found a way around it. This is a major problem. How could CMRs be useful when they don't support this very common and necessary database construct? From everything I have been able to determine, the only solution is to roll your own relationships. Is this a limitation of just JBoss or is it a problem with other containers as well?

                • 5. Re: CMR-Field also CMP-Field
                  Sebastien Petrucci Newbie

                  Hi,

                  I'm also having the same problem.

                  There is also another limitation.
                  Imagine that Bean1 has a relation to Bean2.
                  This relation is mandatory. So you set a NON NULL
                  foreign key in Bean1's table.
                  This is also a problem becoz you cannot set a relation
                  in the ejbCreate() method (setBean2(bean1) will throw an exception). You have to initialize your relation in ejbPostCreate() which already TOO LATE (this is after the INSERT query).
                  Well to resolve this problem you either not set the FK to NOT NULL, or you get rid of the CMR... not very nice.

                  If a field could be CMR and CMP at the same time, it would solve all those problems...

                  Any idea ?

                  Sebastien.

                  • 6. Re: CMR-Field also CMP-Field
                    t g Newbie

                    I have this problem as well. This problem has been floating around the forums for the past month that I've been watching. Does anybody from the JBoss group have any thoughts or information as to a solution to this problem?

                    • 7. Re: CMR-Field also CMP-Field
                      Avery D. Ford Newbie

                      hello lafr,

                      i have a few questions concerning your problem.

                      1) what is the dependency of the entities?
                      2) By predefining the PK/FK combination of Bean2 i assume u hope to get an index to assist with queries?
                      3) What advantage do u hope to gain by having the PK of 'festa' maintained as a direct access CMP when u can navigate the CMR provided.
                      -- i assume this is an issue of performance.
                      -- but even so, this the ejbCreate method of 'Festr' should prevent the creation of 'Festr' entities if a valid 'Festa' local reference is not provided. this maintains ur database integrity since the PK for both entities are none null values.
                      -- adding a unique index to 'Festr' database table could wait 'tuning'.

                      IMHO -
                      ** it seems as though the problem is more of domain/entity/erd mapping and design. ur wanting to model an entity bean *exactly* as its represented in the database when CMR will provide the PK for 'Festr' or 'BeanA' through CMR navigation and calling the 'getPrimaryKey()'.
                      ** otherwise u could rename the FK field name u defined in 'Festr' to NOT match the one generated by CMP/CMR deployment and add another parameter to the 'create()' method representing the PK of 'Festa'. clugy - but whats ur alternative?

                      • 8. Re: CMR-Field also CMP-Field
                        Ignacio de Cordoba Novice

                        Hi there,
                        although I haven't been able to find a worakarround for the problem, you cn have a look at

                        http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ I'd get RC1 of JBoss 3.2 and JBoss 3.0.6 from SourceForge and see if the so long waited feature has been included in these last versions of JBoss. If anyone makes it, please post anything here...

                        Good luck,
                        Ignacio

                        • 9. Re: CMR-Field also CMP-Field
                          Frank Langelage Master

                          The entities are parts of a production order.
                          festa is the head. It contains the information about the the item to be produced, when, how much, ...
                          festr contains the list of materials which are neccessary.
                          febdr contains the papers to printed for the order.

                          It's an existing schema which cannot be changed.
                          I want to access the data in this tables via ejb ProductionOrder with getMaterials(), getPapers(), ...
                          So I wrote a script which generates ejb's from databasemodel with cmr.

                          My "problem" is, that in case of the cmr-field is part of the primary key, it must also be a cmp field.
                          In case it is not part of the pk, the cmr-field must not be a cmp-field, because it is added automatically by cmr.

                          • 10. Almost fixed in 3.2
                            totolaricot Newbie

                            Ignacio,

                            I built JBoss fron CVS (Branch_3_2) this morning. Apparently the problem has been addressed but not fixed: now instead of duplicating the cmr field that is also a PK field, it creates none of the cmr fields.

                            Bean1 (PK = context + name)
                            context
                            name
                            description


                            Bean2 (PK = context + ID)
                            context
                            ID
                            quantity


                            I have a one-to-many relationship between both beans (Bean1 has many Bean2).

                            I declare the cmr fields as follow:
                            <key-field>
                            <field-name>context</field-name>
                            <column-name>context</column-name>
                            </key-field>
                            <key-field>
                            <field-name>name</field-name>
                            <column-name>Bean1_Name</column-name>
                            </key-field>

                            The context column is not duplicated to the Bean2 table, which is what we want. The problem is that the Bean1_Name column is not added either.

                            If I change the declaration as follow:

                            <key-field>
                            <field-name>context</field-name>
                            <column-name>context_foo</column-name>
                            </key-field>
                            <key-field>
                            <field-name>name</field-name>
                            <column-name>Bean1_Name</column-name>
                            </key-field>

                            Both columns are added the the Bean2 table.