3 Replies Latest reply on Aug 29, 2003 3:11 AM by 3dface

    How to restrict removal of beans which referenced by others

    3dface

      Hi,

      I have two entities with 1:n relationship.

      When I delte entity with multiplicity one, relational property of second entity becomes null.

      That behavior is not suitable for me, I want to restrict the removal.

      I have foreign key in the relative table. When I try to delete a record from the first table directly from the database I receive expected result - restriction.

      It seems like JBoss first set relative property to null and then deletes master entity.

      What can I do to avoid this?

      (Database is MySql 4.0; table types is InnoDB, so foreign keys works fine.)

      Thanks.

        • 1. Re: How to restrict removal of beans which referenced by oth
          gchini

          I have the same problem with Oracle 9i.
          I'm using jboss304

          It seems that nobody knows the solution.

          • 2. Re: How to restrict removal of beans which referenced by oth
            3dface

            I found that since 3.2.2RC3 insert-after-ejb-post-create container configuration option is introduced.

            It helps me!

            <container-configurations>
            <container-configuration extends="Standard CMP 2.x EntityBean">
            <container-name>Insert after ejbPostCreate</container-name>
            <insert-after-ejb-post-create>true</insert-after-ejb-post-create>
            </container-configuration>
            </container-configurations>

            • 3. Re: How to restrict removal of beans which referenced by oth
              3dface

              I forgot to say that earlier I have to make cmr field nullable, because it impossible to set relations in ejbCreate method.

              But now I can make it NOT NULL, because I can configure container to execute INSERT statement after ejbPostCreate where I can setup relations.

              Now cmr-field of the child bean can not be setten to null when I trying to remove parent bean and transaction fails. It is what I need.