5 Replies Latest reply on Nov 11, 2001 8:39 PM by Luc Tran Hiep

    Commit options not effect

    Luc Tran Hiep Newbie

      Hi all,
      I design two beans with 1-n relationship. I face to problems when update the bean:
      1. When I delete the master bean, all rows of the detail bean will be deleted by the database. When I create again a master bean has the same primarykey with once before, it's ok. But when I create a detail bean with the same once before, the container throw DuplicateKeyException. Although the detail bean has not exist in the database.
      2. When I delete a bean and create the bean again with the same primary key. All information of the bean before will show again although information in the database is correct.

      My sollution as bellow:
      -When I choose commit option C, the problem 1 is solved but the problem 2 is not solved.
      -When I choose commit option A,B,D the problem 2 is solved but the problem 1 is not solved.

      Please help me ???
      Thank and best regard,
      LucTran

        • 1. Re: Commit options not effect
          Dan Christopherson Newbie

          Problem 1 I'd expect from all options but C. This is just a side effect of using cascaded deletes in the database - JBoss doesn't know that they're being deleted out from under it, so it keeps them cached. Option C fixes this by not caching anything.

          Problem 2, on the other hand...
          Is your delete and create in the same transaction or a different transaction?

          • 2. Re: Commit options not effect
            Luc Tran Hiep Newbie

            Hi danch1,

            Thank for your anwser. I think it's a different transaction. Here is the code I do:

            lookup();
            Application app =home.create("app_id","desc");
            ApplicationPK key=(ApplicationPK)app.getPrimaryKey();
            System.out.println("----------Before----------");
            System.out.println("app_id="+key.toString());
            System.out.println("desc="+app.getDescription());
            app.remove();

            System.out.println("----------After----------");
            Application app_new=home.create("app_id","");
            System.out.println("app_id="+key.toString());
            System.out.println("desc="+app_new.getDescription());

            output:
            -------Before--------
            app_id=app_id
            desc =desc

            -------After---------
            app_id=app_id
            desc =desc

            The desc do not change in two case.

            • 3. Re: Commit options not effect
              Dan Christopherson Newbie

              Is that from a client or a servlet/JSP? Then it _is_ two separate transactions.

              • 4. Re: Commit options not effect
                Dan Christopherson Newbie

                Sorry, I forgot to add "and it should work right."

                • 5. Re: Commit options not effect
                  Luc Tran Hiep Newbie

                  I tested both servlet and main class client. But it's not work. When I re-create the bean with the primary key the same before once. The container executes ejbCreate, ejbStore but not ejbLoad. And when I call business methods, it does not execute ejbLoad. But if I create a new bean, the container executes ejbCreate, ejbLoad, ejbStore.
                  I don't understand why?