To Dep PK bug?

From: Michael Gentry (mgentr..asslight.net)
Date: Fri Nov 05 2010 - 12:57:08 UTC

  • Next message: Michael Gentry: "Re: To Dep PK bug?"

    I kept getting an optimistic locking exception where my PK got nulled
    out, so I set up a simple test case:

    User Table:
    id bigint
    name varchar(50)
    username varchar(20)

    Avatar Table:
    avatarImage blob(100000)
    id biginit

    User is the master table, Avatar the dependent, To Dep PK checked
    going from User to Avatar to map the User PK to the Avatar.

    Code:

            DataContext dataContext = DataContext.createDataContext();

            User admin = dataContext.newObject(User.class);

            admin.setName("Administrator");
            admin.setUsername("admin");

            dataContext.commitChanges();

            admin.setName("The Administrator");

            dataContext.commitChanges();

    The second commitChanges fails with the following SQL:

    INFO: INSERT INTO Users (id, name, username) VALUES (?, ?, ?)
    INFO: [bind: 1->id:200, 2->name:'Administrator', 3->username:'admin']
    INFO: UPDATE Users SET name = ? WHERE id IS NULL AND name = ? AND username = ?
    INFO: [bind: 1->name:'The Administrator', 2->id:NULL,
    3->name:'Administrator', 4->username:'admin']
    org.apache.cayenne.access.OptimisticLockException: [v.3.0 Apr 30 2010
    11:29:33] Optimistic Lock Failure, SQL: [UPDATE Users SET name = ?
    WHERE id IS NULL AND name = ? AND username = ?], WHERE clause
    bindings: [id=NULL, username='admin', name='Administrator']

    The ID gets set to null which is clearly wrong.

    mrg



    This archive was generated by hypermail 2.0.0 : Fri Nov 05 2010 - 12:58:05 UTC