2 Replies Latest reply on May 24, 2002 2:08 AM by Dirk Bogun

    foreign key constraint fails

    Dirk Bogun Newbie

      Hi out there,

      I have a problem with CMP under jboss Version 3.0 RC1 and mysql. I want to create an entity, which has two foreign keys (associations to other classes). I placed the setter for the both foreign keys into the ejbPostCreate-method. Befor the setter can work, the INSERT INTO ... command is sent to the DB and I get an exception, that the row can not be added into the Database, because a foreign key constraint fails.

      When I put the setter into ejbCreate, than an exception occurs, saying that I have to place CMR setter into ejbPostCreate.

      Thanks for your help.


        • 1. Re: foreign key constraint fails
          Sean Carson Newbie

          This problem exists with RC2 and MySQL as well. The only way way I could get around it was to remove the not null attribute on the foreign key column in MySQL. Can a set method for a non null foreign key column be placed in ejbPostCreate()?

          Thanks for your help.

          • 2. Re: foreign key constraint fails
            Dirk Bogun Newbie

            I reported this behavior as a bug. This bug was closed with the comment, that with Version 3.1 it should be possible to set CMR fields before the physical insert into the database.
            Till now, the only workaround is do delete the foreign (indexed row)in the mysql database. But after this, you have no referential integrity. Under Bea Weblogic you can place your setter into the ejbPostCreate() method. I think, with 3.1 it will also be possible with JBoss.