Re: n:m relationship problem. Primary key violations. Query mis-count s

From: Craig Miskell (cmiskel..lbatross.co.nz)
Date: Fri Jan 03 2003 - 18:23:20 EST

  • Next message: Andrus: "Re: pooled connection"

    Ah yes, that's something I just noticed the other day. It's a rather
    unfortunate bug that I completely failed to notice when initially creating
    the flattened relationship support. It's fixed in the latest version in
    CVS, if you're up to getting it that way.

    For the interested: The DataContext maintains a list of "flattened"
    relationships that have been added or removed. It is supposed to clear
    these out after every successful commit, and even has an internal method
    to do so, but somehow, I removed the call to that method after a
    successful commit. Stupid stupid developer. ;-( So basically each commit
    on the same DataContext will try and create the link record again and
    again (and again....)

    Andrus - terribly sorry, but we may need to get a new version out... this
    kind of screws flattened relationships.

    Craig

     On Fri, 3 Jan 2003, Dave Paules wrote:

    > Hi all,
    >
    > I have a many to many relationship that I am updating. Cayenne is
    > duplicating primary key entries.
    >
    > I have a Projects, Employees, and a ProjectsEmployees table in the database.
    >
    > DB schema is below: the *Id fields are Primary Keys
    >
    > Employee
    > employeeId | firstName | lastName
    >
    > Projects
    > projectId | name
    >
    > ProjectsEmployees
    > projectId | employeeId
    >
    >
    > I have tuples in the employee and projects table already.
    > Via code, I was "connecting" tuples in one table to the other by executing
    > aProject.addMember(anEmployee);
    > context.commitChanges;
    >
    > My Cayenne model is using a pass-through relationship via the itermediary
    > ProjectsEmployees table (since that table contains no additional business
    > object info, other than being a middleman table for joins). For example, the
    > Employee object in my Cayenne model has a relationship "projects" that is
    > backed by the db-relationship path TO_projectmembers.TO_projects
    >
    > This works fine until some condition crops up that I am unaware is occuring.
    > The log shows what employees and projects tuples I was trying to "connect".
    > First I have to find the employees I wish to assign (the SELECT call), and
    > then I execute aProject.addMember(anEmployee) which results in the INSERT
    > calls that modify the ProjectsEmployees table.
    >
    > When the error occurs, I have connected employees Philips and Paules to
    > project SBIR-80. The next transaction is begun where I am trying to add
    > employees Paules and Corrigan to project Anvil Phase II. For some reason, on
    > context.commitChanges for these two changes, Cayenne is attempting to re-add
    > Philips to project SBIR-80. Why? What's more, is that QueryLogger reports
    > "will run 4 queries" at that point. But there aren't 4 queries to run. There
    > are 3. And there shouldn't even be that many. There should be two. What
    > gives?
    >
    > <errorlog>
    >
    > WARN QueryLogger: --- will run 1 query.
    > WARN QueryLogger: SELECT t0.firstName, t0.lastName, t0.title, t0.managerId,
    > t0.employeeId FROM employee t0 WHERE (UPPER(t0.lastName) LIKE UPPER(?)) OR
    > (UPPER(t0.lastName) LIKE UPPER(?)) [params: 'Paules', 'Philips']
    > WARN QueryLogger: === returned 2 rows. - took 0 ms.
    > found 2 employees
    > Adding Philips to project SBIR-80
    > Adding Paules to project SBIR-80
    > WARN QueryLogger: --- will run 2 queries.
    > WARN QueryLogger: INSERT INTO projectmembers (projectId, employeeId) VALUES
    > (?, ?) [params: 1, 4]
    > WARN QueryLogger: === updated 1 row.
    > WARN QueryLogger: INSERT INTO projectmembers (projectId, employeeId) VALUES
    > (?, ?) [params: 1, 1]
    > WARN QueryLogger: === updated 1 row.
    > WARN QueryLogger: +++ transaction committed.
    >
    > WARN QueryLogger: --- will run 1 query.
    > WARN QueryLogger: SELECT t0.firstName, t0.lastName, t0.title, t0.managerId,
    > t0.employeeId FROM employee t0 WHERE (UPPER(t0.lastName) LIKE UPPER(?)) OR
    > (UPPER(t0.lastName) LIKE UPPER(?)) [params: 'Paules', 'Corrigan']
    > WARN QueryLogger: === returned 2 rows. - took 10 ms.
    > found 2 employees
    > Adding Paules to project Anvil Phase II
    > Adding Corrigan to project Anvil Phase II
    > WARN QueryLogger: --- will run 4 queries.
    > WARN QueryLogger: INSERT INTO projectmembers (projectId, employeeId) VALUES
    > (?, ?) [params: 2, 1]
    > WARN QueryLogger: === updated 1 row.
    > WARN QueryLogger: INSERT INTO projectmembers (projectId, employeeId) VALUES
    > (?, ?) [params: 2, 5]
    > WARN QueryLogger: === updated 1 row.
    > WARN QueryLogger: INSERT INTO projectmembers (projectId, employeeId) VALUES
    > (?, ?) [params: 1, 4]
    > WARN QueryLogger: *** error.
    > java.sql.SQLException: Invalid argument value: Duplicate entry '1-4' for key
    > 1
    >
    > </errorlog>
    >
    > Please help.
    > Dave Paules
    > Quantum Leap Innovations
    > www.leapworks.com
    >



    This archive was generated by hypermail 2.0.0 : Fri Jan 03 2003 - 18:19:27 EST