4 Replies Latest reply on Aug 18, 2004 9:57 AM by sbrbot

    Cascade delete

    sbrbot

      I work with JBoss v3.2.3, MySQL v4.0.20d and MySQL Connector/J 3.0.14 (stable) JDBC driver.

      I created one-to-many relationship between CustomerEJB-OrderEJB CMP beans. There is referential integrity between CUSTOMERS and ORDERS tables also cascading delete feature is set and it works if I delete Customer row from DB tool. I tracked JDBC connection to see what JBoss does under the hood when I try to delete a row from customer table (Customer.remove()). First I tried it without <cascade-delete/> in ejb-jar.xml (of course DB complaints about that), and after that I tried it with <cascade-delete/> but the situation is complitely the same. But the SQL under the hood was complitely the same. JBoss tries to set foreign keys in ORDERS table to null and it is not allowed by database model (I realy do not want to have orphan records in ORDERS table). Ok, when I use <batch-cascade-delete/> it works but I think that <cascade-delete/> is intended exactly for the purpose that <batch-cascade-delete/> does.

        • 1. settings of Postgresql-Datasource from Eclipse IDE.
          sbrbot

          Hi,

          Thks for the wonderfull featured Tutorials.I have successfully implemented most of it.
          well I am in need of details of various setting required if as option oh Hypersonic Database / I am using postgresql7.0 need to used.

          The details i have done are.
          1. postgressql.jar file have copied in jbossx.x.x\lib directory.
          2. postgres-ds.xml file have been edited and copied in deploy directory appr.

          well further i have bit confusion how my

          standardjbosscmp-jdbc
          standardjaws
          standardjboss xml files should i edit.
          I purposely not moved further on doing R&D but it would be great help to save my time .

          THks in before

          Mitdin

          • 2. Re: Cascade delete
            aloubyansky

            Read the wiki page on batch-cascade-delete which describes why cascade-delete is the default.

            • 3. Re: Cascade delete
              sbrbot

              I did exactly that. I read your article on WIKI and found how to use <batch-cascade-delete/>. Without this article I wouldn't even know about <batch-cascade-delete/> DD parameter. (BTW, I tried to do some changes on this article but encountered difficulties to submit it. WIKI editor cripled my response! Something is wrong with this WIKI editor! The preview looked just fine but when I submitted response it was clipled! Take a look.)

              You explained how JBoss manages cascade deletion of related records:

              * destroy relationship;
              * synchronize the state (set foreign key fields to NULL in the database to be able to remove the parent);
              * remove the parent instance;
              * for each child repeat the procedure starting from 1.

              IMHO this is wrong approach. In big majority of cases you will not be able to destroy relationship regarding database referential integrities. Also, more than often foreign keys are NOT NULL columns. So this listed approach will work only with database models without real integrity constraints implemented in it. Ask DBA's and other people working with DB's what they think about databases without referential integrities!

              My question is what is the difference if I set <cascade-delete/> or not? As it has been mentioned, I tracked JDBC traffic of JBoss and find out that there's no difference for JBoss if I set <cascade-delete/> or not! JBoss sends the same SQL trying to destroy relationships regardles of <cascade-delete/>.

              • 4. Re: Cascade delete
                aloubyansky

                I restored the page. Read starting from "The EJB2.1 spec defines the cascade-delete protocol in "10.3.4.2 Cascade-delete" as:"