Hi All,
I'm having problem to use the X.removeFromYArray(y) function to delete the
1:n relationship records in the database. I'm using tomcat 4.1.17 + Struts
1.1 + Cayenne-1.0a5-1.
It is a project issue management system. There are 4 tables in the user
management section - Project, Users, Role & ProjectUsers. The tables are
defined as following (in brief):
Project:
ProjectId int PK
ProjectName varchar(100)
Users: (oops, can't use User in MSSQL, don't get confused below... )
UserId int PK
Login varchar(50)
Password varchar(20)
Role:
RoleId int PK
RoleDesc varchar(50)
ProjectUsers:
ProjectId int FK
UserId int FK
RoleId int FK
ProjectUsers table holds all the information how the user can access the
system. When I come to the section to edit/modify the user roles, I need to
delete the records in this table for a user related to a particular project,
then add the new ones. The logic related to the deletion process is as
following:
// 1. get the user object
Users users = getUsers(ctxt, login);
// 2. get the all related projectuser objects(regardless what
project for now)
List projectuserss = user.getProjectusersArray();
// 3. iterating through the projectusers list and remove them:
for (int i=0; i<projectuserss.size(); i++)
user.removeFromProjectusersArray((Projectusers)projectuserss.get(i));
// 4. finally, commit the changes
ctxt.commitChanges(Level.WARN);
No matter what I did, just can't see the DELETE statement generated by
Cayenne from the tomcat running console, and the database records are not
removed obviously.
The users object and the related projectuserss list returned by the
statements can be verified they are all correct. I've tried to set the users
object consistence state by using
users.setPersistenceState(PersistenceStte.MODIFIED) right after I get the
users object, eventhough it is not the case in the
RemovePaintingFroGalleryAction example.
On the other hand, the users.addToProjectusersArray(projectusers) function
is working perfectly (I've added lot of duplicated records ;- )
What I'm doing wrong here? Can anyone point me to the right direction?
Thanks for your help!
Bill
This archive was generated by hypermail 2.0.0 : Tue Jan 14 2003 - 17:28:19 EST