Re: Problems with FK contraints in Object creation.

From: Jorge Sopena (jsopen..idsa.es)
Date: Wed Dec 01 2004 - 05:13:48 EST

  • Next message: Joaquin Arias Buendia: "Problem commiting objects"

    Yes,
    It's MySQL 4 where my tables are InnoDB so FK constraints are supported.
    If they were MyISAM type FK constraints wouldn't be supported.

    Thanks for the advice, now it's working correctly.

    Jorge

    Andrus Adamchik wrote:

    >Jorge,
    >
    >You don't mention what DB you are using. Is it MySQL 4 by any chance?
    >
    >Cayenne does proper ordering of insert/update/delete operations, however
    >if it thinks that the target DB does not support FK constraints, it
    >doesn't bother to do the ordering... MySQLAdapter still lives in MySQL 3
    >world, assuming that there is no constraints. So you have to explicitly
    >turn on the ordering. Just follow the advise iven here:
    >
    >http://www.objectstyle.org/cayenne/lists/cayenne-user/2004/07/0054.html
    >
    >Hope this helps.
    >
    >Andrus
    >
    >
    >
    >
    >>Hi,
    >>I'm having problems when I create two objects and commit them. When
    >>there is a FK between them, I get a
    >>"java.sql.SQLException: General error, message from server: "Cannot add
    >> or update a child row: a foreign key constraint fails"
    >>
    >>The real problem is more complex but I test this simple case and the
    >>problem arises too.
    >>I have two objects, SmsUser and Profile. SmsUser has a FK to Profile.
    >>When I create both objects and try to commit them, I've got the
    >>exception. It's because Cayenne is trying to save the SmsUser first,
    >>then the Profile. The log generated is:
    >>
    >> INFO QueryLogger: LOCK TABLES AUTO_PK_SUPPORT WRITE
    >> INFO QueryLogger: SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE
    >> TABLE_NAME = 'profile'
    >> INFO QueryLogger: UPDATE AUTO_PK_SUPPORT SET NEXT_ID = NEXT_ID + 20
    >>WHERE TABLE_NAME = 'profile' AND NEXT_ID = 260
    >> INFO QueryLogger: UNLOCK TABLES
    >> INFO QueryLogger: LOCK TABLES AUTO_PK_SUPPORT WRITE
    >> INFO QueryLogger: SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE
    >> TABLE_NAME = 'smsuser'
    >> INFO QueryLogger: UPDATE AUTO_PK_SUPPORT SET NEXT_ID = NEXT_ID + 20
    >>WHERE TABLE_NAME = 'smsuser' AND NEXT_ID = 320
    >> INFO QueryLogger: UNLOCK TABLES
    >> INFO QueryLogger: --- transaction started.
    >> INFO QueryLogger: --- will run 2 queries.
    >> INFO QueryLogger: INSERT INTO smsuser (Name, Password,
    >> Profile_idProfile, Username, idUser) VALUES (?, ?, ?, ?, ?)
    >> INFO QueryLogger: [bind: 'kiko', 'º¨Äçg4×ÅEX¼-_', 260, 'kiko',
    >>320] INFO QueryLogger: *** error.
    >> java.sql.SQLException: General error, message from server: "Cannot
    >>add or update a child row: a foreign key constraint fails"
    >>
    >>I've seen there is a Issue(CAY-87
    >><http://objectstyle.org/jira/secure/ViewIssue.jspa?key=CAY-87>) open
    >>about this problem but when there is a relationship cycle. This case I
    >>think is differente and a very common situation.
    >>I'm working with Cayenne-1.1RC3.
    >>I also attach my Database Map, if it's useful to find the problem.
    >>
    >>Any hint?
    >>
    >>Thanks!!!
    >>
    >>Jorge
    >>
    >>
    >
    >
    >
    >
    >
    >

    -- 
    



    This archive was generated by hypermail 2.0.0 : Wed Dec 01 2004 - 05:09:25 EST