3 Replies Latest reply on Nov 15, 2007 3:41 AM by sstrenn

    seam-gen entities: cascading bug or accepted behavior?

      Folks,

      When seam-gen generates an entity with a one-to-many association to another entity, it appears to always set the cascade attribute to CascadeType.ALL.

      My sense is that this is incorrect behavior when the foreign key's constraint in the database is set to ON DELETE RESTRICT.

      Is this an "undocumented feature", or an misunderstanding of the expected behavior on my part. If so, could you please give me a quick explanation of why CascadeType.ALL is correct when a foreign key's constraint is ON DELETE RESTRICT.

      Thanks,
      Stephen

        • 1. Re: seam-gen entities: cascading bug or accepted behavior?
          maxandersen

          it's a default behavior - there isn't implemented suport for taking into account db specific constraints.

          Open a feature request against hibernate tools ;)

          p.s. you can use reveng.xml to control parts of this.

          • 2. Re: seam-gen entities: cascading bug or accepted behavior?

            Max,

            Thanks for clearing that up. I'll submit a feature request to the hibernate tools project to adjust the cascade attribute so that it matches the database-defined behavior. I'll also submit a request to the seam team for a mention of this behavior in the "Getting started with Seam, using seam-gen" section of the reference.

            BTW - just as an example of what can happen if one does not change the "default behavior":

            Delete a (sales) employee. This cascades to delete all of the customers associated with that employee, which, in turn, cascades to delete all of the sales orders and line items associated with that customer. Also, if the employee table has a self-referential foreign key to identify the employee's boss, a whole chain of other employees (and their customers and sales orders) can be deleted...

            Stephen

            • 3. Re: seam-gen entities: cascading bug or accepted behavior?

              I have submitted the feature request to the hibernate tools team.

              I have also added an entry on the Seam Problems FAQ: http://wiki.jboss.org/wiki/Wiki.jsp?page=SeamProblemsFAQ