9 Replies Latest reply on Mar 8, 2005 5:42 AM by jbm166

    Adding CMR fails

    jbm166

      Hello,

      I m facing a problem with JBoss 3.2.5 which does not exist under JBoss 3.2.2.

      Here is my problem :

      I have 2 entities A and B, with a 1-n relationship.
      When we add many B to a A we do , inside A :

      while(B_lentgh) {
      BLocalHome home = BUtil.getLocalHome();

      // Create the B entity
      BLocal relation = home.create(bDTO);

      // Add the new B entity to A
      getB().add(relation);
      }


      So this code is executed by the entity A.
      Problem, it seems that the "getB().add()" method is not commited right after the B entity creation.

      Therefore when we get inside the loop for the second time a new B entity is created, but the previous one is still not added to A (it's foreign key is null)

      Because I have DB constraints on the foreign key (unique constraint coupled with another attribute), I get an oracle exception.


      I hope that this pseudo code is understandable :-)
      Also note that this part is generated by XDoclet (in the aCMP class).
      And again, this is working under 3.2.2 but not 3.2.5 (and we need 3.2.5)

      Thanks for your help.
      J&B

        • 1. Re: Adding CMR fails
          jbm166

          I need a simple testcase that shows the difference. So far I believe you are doing something wrong. If you have enough information for me to reproduce this, please, open a Jira issue on jira.jboss.com.

          • 2. Re: Adding CMR fails
            aloubyansky
            • 3. Re: Adding CMR fails
              jbm166

              Hi,

              Thanks for your answer.

              In JBoss 3.2.2, obviously the getB().add(relation) was commited immediately, since when the loop was iterating the second round the unique constraint was not triggered when creating a new B entity (Meaning that the foreign key had been set)

              Where it is clear that in 3.2.5 getB().add() is not commited inside the loop but after, so that the foreign key is not immediately added.

              I tried the insertAfterEjbPostCreate and it did not work better.
              I don't think it would help anyway, since in this case the A entity already exist. We only create B entities that we map to A.

              And this mapping happens in this method, not in the ejbPostCreate method of the B entity.


              It is quite a surprising problem, because this code is generated by XDoclet and I found also the same code example of "howto add CMR" in different EJB manuals.

              J&B

              • 4. Re: Adding CMR fails
                aloubyansky

                Do you have a testcase that I can run on 3.2.2 and 3.2.5 and see what you are talking about? Updates were always committed at the end of the tx in all versions or other times when synchronization is required but not after adding CMR value.

                • 5. Re: Adding CMR fails
                  jbm166

                  Hello,

                  No I don't really have any testcase.
                  Fact is that I m not an expert concerning transactions and so on, so I m actually wondering if problem comes from something I did wrong. However same code seems to behave differently in 3.2.2 and 3.2.5.

                  I could maybe send you couple of classes if that's ok ?

                  • 6. Re: Adding CMR fails
                    aloubyansky

                    I need a simple testcase that shows the difference. So far I believe you are doing something wrong. If you have enough information for me to reproduce this, please, open a Jira issue on jira.jboss.com.

                    • 7. Re: Adding CMR fails
                      jbm166

                      Hello,

                      I added it to jira.
                      Here is the KEY : JBAS-72

                      • 8. Re: Adding CMR fails
                        aloubyansky

                        I will look at it. Thanks.
                        It's possible that there was something wrong with 3.2.2 but I need to check.

                        • 9. Re: Adding CMR fails
                          jbm166

                          Hello,

                          Is this thread still alive ?
                          Has somebody had time to check this matter ?

                          Thanks.
                          Regards.

                          J&B