why I can't remove the table records this way?

From: Bill Fan (bil..anscom.com.au)
Date: Wed Mar 31 2004 - 06:32:27 EST

  • Next message: Andrus Adamchik: "Re: Why "SELECT DISTINCT ..." is generated?"

    Hi,
     
    I'm using the latest Cayenne 1.0.7
     
    I have the following function which works fine with the original developed
    intranet system(works on 1.0a5). It is used to manage the relationship
    between the Project, User & Role. The inter-reference table is ProjectUsers.
     
    The table structure are as following:
     
    Project:
        ProjectId int PK
        ProjectName varchar
        ....
     
    Users:
        UserId int PK
        Firstname varchar
        ...
     
    Role:
        RoleId int PK
        Role
        ....
     
    ProjectUsers:
        ProjectId int PK, FK
        UserId int PK, FK
        RoleId int PK, FK
        
     
    With the following block of code, I was trying to delete any existing
    records in the ProjectUsers table for a user first before I could add the
    new records in. But it seemed there was no action triggered. I couldn't see
    any delete sql statement generated from the log file, and the later insert
    statement failed as it was trying to add duplicate PK in the table.
     
     
    ===============================================================
    // projectusersArray has the Projectusers objects to be removed....
     
     Iterator iter = (new ArrayList(projectusersArray)).iterator();
     while (iter.hasNext())
     {
     Projectusers obj = (Projectusers)iter.next();
     iter.remove();
     
     log.debug("=========> obj.getToUsers().getFirstname()=" +
    obj.getToUsers().getFirstname());
     log.debug("=========> obj.getToUsers().getLastname()=" +
    obj.getToUsers().getLastname());
     log.debug("=========> obj.getToUsers().getLogin()=" +
    obj.getToUsers().getLogin());
     
     users.removeFromProjectusersArray( obj );
     // delet it !!
     ctxt.deleteObject(obj);
     }
    ===============================================================
     
     
    I'm taking the exact data model and the functions from the existing working
    system to try to implement a new one, but it did not work as expected.
     
    Appreciate any help!
     
     
    Thanks,
    Bill



    This archive was generated by hypermail 2.0.0 : Wed Mar 31 2004 - 06:31:24 EST