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

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Apr 01 2004 - 16:03:39 EST

  • Next message: Alexander Lamb: "Newby question about Cayenne, threads and EOF comparison"

    Bill,

    the only thing I can see missing from the code is
    "ctxt.commitChanges()", but I assume you just forgot to include it in
    your message... still worth checking though :-).

    If you still have this problem, please submit a bug report via JIRA at
    http://objectstyle.org/cayenne/bugs-features.html and attach your
    DataMap to the report. I am not aware of any cases when
    "ctxt.deleteObject(obj);" is quietly ignored.

    Andrus

    On Mar 31, 2004, at 6:32 AM, Bill Fan wrote:

    > 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 : Thu Apr 01 2004 - 16:03:45 EST